Fix PR#.
[official-gcc.git] / gcc / toplev.c
blob38d8eaf80afb28a6da31afc3debd4c248772656a
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
11 version.
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
16 for more details.
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. */
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"
84 #include "tree-pass.h"
85 #include "gimple.h"
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
89 #endif
91 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
92 #include "dbxout.h"
93 #endif
95 #ifdef SDB_DEBUGGING_INFO
96 #include "sdbout.h"
97 #endif
99 #ifdef XCOFF_DEBUGGING_INFO
100 #include "xcoffout.h" /* Needed for external data
101 declarations for e.g. AIX 4.x. */
102 #endif
104 static void general_init (const char *);
105 static void do_compile (void);
106 static void process_options (void);
107 static void backend_init (void);
108 static int lang_dependent_init (const char *);
109 static void init_asm_output (const char *);
110 static void finalize (void);
112 static void crash_signal (int) ATTRIBUTE_NORETURN;
113 static void setup_core_dumping (void);
114 static void compile_file (void);
116 /* Nonzero to dump debug info whilst parsing (-dy option). */
117 static int set_yydebug;
119 /* True if we don't need a backend (e.g. preprocessing only). */
120 static bool no_backend;
122 /* Length of line when printing switch values. */
123 #define MAX_LINE 75
125 /* Name of program invoked, sans directories. */
127 const char *progname;
129 /* Copy of argument vector to toplev_main. */
130 static const char **save_argv;
132 /* Name of top-level original source file (what was input to cpp).
133 This comes from the #-command at the beginning of the actual input.
134 If there isn't any there, then this is the cc1 input file name. */
136 const char *main_input_filename;
138 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
139 to optimize and default_debug_hooks in process_options (). */
140 #define AUTODETECT_VALUE 2
142 /* Current position in real source file. */
144 location_t input_location;
146 struct line_maps *line_table;
148 /* Name to use as base of names for dump output files. */
150 const char *dump_base_name;
152 /* Name to use as a base for auxiliary output files. */
154 const char *aux_base_name;
156 /* Prefix for profile data files */
157 const char *profile_data_prefix;
159 /* A mask of target_flags that includes bit X if X was set or cleared
160 on the command line. */
162 int target_flags_explicit;
164 /* Debug hooks - dependent upon command line options. */
166 const struct gcc_debug_hooks *debug_hooks;
168 /* Debug hooks - target default. */
170 static const struct gcc_debug_hooks *default_debug_hooks;
172 /* Other flags saying which kinds of debugging dump have been requested. */
174 int rtl_dump_and_exit;
175 int flag_print_asm_name;
176 enum graph_dump_types graph_dump_format;
178 /* Name for output file of assembly code, specified with -o. */
180 const char *asm_file_name;
182 /* Nonzero means do optimizations. -O.
183 Particular numeric values stand for particular amounts of optimization;
184 thus, -O2 stores 2 here. However, the optimizations beyond the basic
185 ones are not controlled directly by this variable. Instead, they are
186 controlled by individual `flag_...' variables that are defaulted
187 based on this variable. */
189 int optimize = 0;
191 /* Nonzero means optimize for size. -Os.
192 The only valid values are zero and nonzero. When optimize_size is
193 nonzero, optimize defaults to 2, but certain individual code
194 bloating optimizations are disabled. */
196 int optimize_size = 0;
198 /* The FUNCTION_DECL for the function currently being compiled,
199 or 0 if between functions. */
200 tree current_function_decl;
202 /* Set to the FUNC_BEGIN label of the current function, or NULL
203 if none. */
204 const char * current_function_func_begin_label;
206 /* Nonzero means to collect statistics which might be expensive
207 and to print them when we are done. */
208 int flag_detailed_statistics = 0;
210 /* A random sequence of characters, unless overridden by user. */
211 static const char *flag_random_seed;
213 /* A local time stamp derived from the time of compilation. It will be
214 zero if the system cannot provide a time. It will be -1u, if the
215 user has specified a particular random seed. */
216 unsigned local_tick;
218 /* -f flags. */
220 /* Nonzero means `char' should be signed. */
222 int flag_signed_char;
224 /* Nonzero means give an enum type only as many bytes as it needs. A value
225 of 2 means it has not yet been initialized. */
227 int flag_short_enums;
229 /* Nonzero if structures and unions should be returned in memory.
231 This should only be defined if compatibility with another compiler or
232 with an ABI is needed, because it results in slower code. */
234 #ifndef DEFAULT_PCC_STRUCT_RETURN
235 #define DEFAULT_PCC_STRUCT_RETURN 1
236 #endif
238 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
240 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
242 /* 0 means straightforward implementation of complex divide acceptable.
243 1 means wide ranges of inputs must work for complex divide.
244 2 means C99-like requirements for complex multiply and divide. */
246 int flag_complex_method = 1;
248 /* Nonzero means we should be saving declaration info into a .X file. */
250 int flag_gen_aux_info = 0;
252 /* Specified name of aux-info file. */
254 const char *aux_info_file_name;
256 /* Nonzero if we are compiling code for a shared library, zero for
257 executable. */
259 int flag_shlib;
261 /* Generate code for GNU or NeXT Objective-C runtime environment. */
263 #ifdef NEXT_OBJC_RUNTIME
264 int flag_next_runtime = 1;
265 #else
266 int flag_next_runtime = 0;
267 #endif
269 /* Set to the default thread-local storage (tls) model to use. */
271 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
273 /* Nonzero means change certain warnings into errors.
274 Usually these are warnings about failure to conform to some standard. */
276 int flag_pedantic_errors = 0;
278 /* Nonzero means make permerror produce warnings instead of errors. */
280 int flag_permissive = 0;
282 /* -dA causes debug commentary information to be produced in
283 the generated assembly code (to make it more readable). This option
284 is generally only of use to those who actually need to read the
285 generated assembly code (perhaps while debugging the compiler itself).
286 Currently, this switch is only used by dwarfout.c; however, it is intended
287 to be a catchall for printing debug information in the assembler file. */
289 int flag_debug_asm = 0;
291 /* -dP causes the rtl to be emitted as a comment in assembly. */
293 int flag_dump_rtl_in_asm = 0;
295 /* When non-NULL, indicates that whenever space is allocated on the
296 stack, the resulting stack pointer must not pass this
297 address---that is, for stacks that grow downward, the stack pointer
298 must always be greater than or equal to this address; for stacks
299 that grow upward, the stack pointer must be less than this address.
300 At present, the rtx may be either a REG or a SYMBOL_REF, although
301 the support provided depends on the backend. */
302 rtx stack_limit_rtx;
304 /* Nonzero if we should track variables. When
305 flag_var_tracking == AUTODETECT_VALUE it will be set according
306 to optimize, debug_info_level and debug_hooks in process_options (). */
307 int flag_var_tracking = AUTODETECT_VALUE;
309 /* Type of stack check. */
310 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
312 /* True if the user has tagged the function with the 'section'
313 attribute. */
315 bool user_defined_section_attribute = false;
317 /* Values of the -falign-* flags: how much to align labels in code.
318 0 means `use default', 1 means `don't align'.
319 For each variable, there is an _log variant which is the power
320 of two not less than the variable, for .align output. */
322 int align_loops_log;
323 int align_loops_max_skip;
324 int align_jumps_log;
325 int align_jumps_max_skip;
326 int align_labels_log;
327 int align_labels_max_skip;
328 int align_functions_log;
330 typedef struct
332 const char *const string;
333 int *const variable;
334 const int on_value;
336 lang_independent_options;
338 /* Nonzero if subexpressions must be evaluated from left-to-right. */
339 int flag_evaluation_order = 0;
341 /* The user symbol prefix after having resolved same. */
342 const char *user_label_prefix;
344 static const param_info lang_independent_params[] = {
345 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
346 { OPTION, DEFAULT, false, MIN, MAX, HELP },
347 #include "params.def"
348 #undef DEFPARAM
349 { NULL, 0, false, 0, 0, NULL }
352 /* Output files for assembler code (real compiler output)
353 and debugging dumps. */
355 FILE *asm_out_file;
356 FILE *aux_info_file;
357 FILE *dump_file = NULL;
358 const char *dump_file_name;
360 /* The current working directory of a translation. It's generally the
361 directory from which compilation was initiated, but a preprocessed
362 file may specify the original directory in which it was
363 created. */
365 static const char *src_pwd;
367 /* Initialize src_pwd with the given string, and return true. If it
368 was already initialized, return false. As a special case, it may
369 be called with a NULL argument to test whether src_pwd has NOT been
370 initialized yet. */
372 bool
373 set_src_pwd (const char *pwd)
375 if (src_pwd)
377 if (strcmp (src_pwd, pwd) == 0)
378 return true;
379 else
380 return false;
383 src_pwd = xstrdup (pwd);
384 return true;
387 /* Return the directory from which the translation unit was initiated,
388 in case set_src_pwd() was not called before to assign it a
389 different value. */
391 const char *
392 get_src_pwd (void)
394 if (! src_pwd)
396 src_pwd = getpwd ();
397 if (!src_pwd)
398 src_pwd = ".";
401 return src_pwd;
404 /* Called when the start of a function definition is parsed,
405 this function prints on stderr the name of the function. */
406 void
407 announce_function (tree decl)
409 if (!quiet_flag)
411 if (rtl_dump_and_exit)
412 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
413 else
414 fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2));
415 fflush (stderr);
416 pp_needs_newline (global_dc->printer) = true;
417 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
421 /* Initialize local_tick with the time of day, or -1 if
422 flag_random_seed is set. */
424 static void
425 init_local_tick (void)
427 if (!flag_random_seed)
429 /* Get some more or less random data. */
430 #ifdef HAVE_GETTIMEOFDAY
432 struct timeval tv;
434 gettimeofday (&tv, NULL);
435 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
437 #else
439 time_t now = time (NULL);
441 if (now != (time_t)-1)
442 local_tick = (unsigned) now;
444 #endif
446 else
447 local_tick = -1;
450 /* Set up a default flag_random_seed and local_tick, unless the user
451 already specified one. Must be called after init_local_tick. */
453 static void
454 init_random_seed (void)
456 unsigned HOST_WIDE_INT value;
457 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
459 value = local_tick ^ getpid ();
461 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
462 flag_random_seed = random_seed;
465 /* Obtain the random_seed string. Unless NOINIT, initialize it if
466 it's not provided in the command line. */
468 const char *
469 get_random_seed (bool noinit)
471 if (!flag_random_seed && !noinit)
472 init_random_seed ();
473 return flag_random_seed;
476 /* Modify the random_seed string to VAL. Return its previous
477 value. */
479 const char *
480 set_random_seed (const char *val)
482 const char *old = flag_random_seed;
483 flag_random_seed = val;
484 return old;
487 /* Decode the string P as an integral parameter.
488 If the string is indeed an integer return its numeric value else
489 issue an Invalid Option error for the option PNAME and return DEFVAL.
490 If PNAME is zero just return DEFVAL, do not call error. */
493 read_integral_parameter (const char *p, const char *pname, const int defval)
495 const char *endp = p;
497 while (*endp)
499 if (ISDIGIT (*endp))
500 endp++;
501 else
502 break;
505 if (*endp != 0)
507 if (pname != 0)
508 error ("invalid option argument %qs", pname);
509 return defval;
512 return atoi (p);
515 /* When compiling with a recent enough GCC, we use the GNU C "extern inline"
516 for floor_log2 and exact_log2; see toplev.h. That construct, however,
517 conflicts with the ISO C++ One Definition Rule. */
519 #if GCC_VERSION < 3004 || !defined (__cplusplus)
521 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
522 If X is 0, return -1. */
525 floor_log2 (unsigned HOST_WIDE_INT x)
527 int t = 0;
529 if (x == 0)
530 return -1;
532 #ifdef CLZ_HWI
533 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
534 #else
535 if (HOST_BITS_PER_WIDE_INT > 64)
536 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
537 t += 64;
538 if (HOST_BITS_PER_WIDE_INT > 32)
539 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
540 t += 32;
541 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
542 t += 16;
543 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
544 t += 8;
545 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
546 t += 4;
547 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
548 t += 2;
549 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
550 t += 1;
551 #endif
553 return t;
556 /* Return the logarithm of X, base 2, considering X unsigned,
557 if X is a power of 2. Otherwise, returns -1. */
560 exact_log2 (unsigned HOST_WIDE_INT x)
562 if (x != (x & -x))
563 return -1;
564 #ifdef CTZ_HWI
565 return x ? CTZ_HWI (x) : -1;
566 #else
567 return floor_log2 (x);
568 #endif
571 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
573 /* Handler for fatal signals, such as SIGSEGV. These are transformed
574 into ICE messages, which is much more user friendly. In case the
575 error printer crashes, reset the signal to prevent infinite recursion. */
577 static void
578 crash_signal (int signo)
580 signal (signo, SIG_DFL);
582 /* If we crashed while processing an ASM statement, then be a little more
583 graceful. It's most likely the user's fault. */
584 if (this_is_asm_operands)
586 output_operand_lossage ("unrecoverable error");
587 exit (FATAL_EXIT_CODE);
590 internal_error ("%s", strsignal (signo));
593 /* Arrange to dump core on error. (The regular error message is still
594 printed first, except in the case of abort().) */
596 static void
597 setup_core_dumping (void)
599 #ifdef SIGABRT
600 signal (SIGABRT, SIG_DFL);
601 #endif
602 #if defined(HAVE_SETRLIMIT)
604 struct rlimit rlim;
605 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
606 fatal_error ("getting core file size maximum limit: %m");
607 rlim.rlim_cur = rlim.rlim_max;
608 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
609 fatal_error ("setting core file size limit to maximum: %m");
611 #endif
612 diagnostic_abort_on_error (global_dc);
616 /* Strip off a legitimate source ending from the input string NAME of
617 length LEN. Rather than having to know the names used by all of
618 our front ends, we strip off an ending of a period followed by
619 up to five characters. (Java uses ".class".) */
621 void
622 strip_off_ending (char *name, int len)
624 int i;
625 for (i = 2; i < 6 && len > i; i++)
627 if (name[len - i] == '.')
629 name[len - i] = '\0';
630 break;
635 /* Output a quoted string. */
637 void
638 output_quoted_string (FILE *asm_file, const char *string)
640 #ifdef OUTPUT_QUOTED_STRING
641 OUTPUT_QUOTED_STRING (asm_file, string);
642 #else
643 char c;
645 putc ('\"', asm_file);
646 while ((c = *string++) != 0)
648 if (ISPRINT (c))
650 if (c == '\"' || c == '\\')
651 putc ('\\', asm_file);
652 putc (c, asm_file);
654 else
655 fprintf (asm_file, "\\%03o", (unsigned char) c);
657 putc ('\"', asm_file);
658 #endif
661 /* Output a file name in the form wanted by System V. */
663 void
664 output_file_directive (FILE *asm_file, const char *input_name)
666 int len;
667 const char *na;
669 if (input_name == NULL)
670 input_name = "<stdin>";
671 else
672 input_name = remap_debug_filename (input_name);
674 len = strlen (input_name);
675 na = input_name + len;
677 /* NA gets INPUT_NAME sans directory names. */
678 while (na > input_name)
680 if (IS_DIR_SEPARATOR (na[-1]))
681 break;
682 na--;
685 #ifdef ASM_OUTPUT_SOURCE_FILENAME
686 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
687 #else
688 fprintf (asm_file, "\t.file\t");
689 output_quoted_string (asm_file, na);
690 fputc ('\n', asm_file);
691 #endif
694 /* A subroutine of wrapup_global_declarations. We've come to the end of
695 the compilation unit. All deferred variables should be undeferred,
696 and all incomplete decls should be finalized. */
698 void
699 wrapup_global_declaration_1 (tree decl)
701 /* We're not deferring this any longer. Assignment is conditional to
702 avoid needlessly dirtying PCH pages. */
703 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
704 && DECL_DEFER_OUTPUT (decl) != 0)
705 DECL_DEFER_OUTPUT (decl) = 0;
707 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
708 lang_hooks.finish_incomplete_decl (decl);
711 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
712 needs to be output. Return true if it is output. */
714 bool
715 wrapup_global_declaration_2 (tree decl)
717 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
718 return false;
720 /* Don't write out static consts, unless we still need them.
722 We also keep static consts if not optimizing (for debugging),
723 unless the user specified -fno-keep-static-consts.
724 ??? They might be better written into the debug information.
725 This is possible when using DWARF.
727 A language processor that wants static constants to be always
728 written out (even if it is not used) is responsible for
729 calling rest_of_decl_compilation itself. E.g. the C front-end
730 calls rest_of_decl_compilation from finish_decl.
731 One motivation for this is that is conventional in some
732 environments to write things like:
733 static const char rcsid[] = "... version string ...";
734 intending to force the string to be in the executable.
736 A language processor that would prefer to have unneeded
737 static constants "optimized away" would just defer writing
738 them out until here. E.g. C++ does this, because static
739 constants are often defined in header files.
741 ??? A tempting alternative (for both C and C++) would be
742 to force a constant to be written if and only if it is
743 defined in a main file, as opposed to an include file. */
745 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
747 struct varpool_node *node;
748 bool needed = true;
749 node = varpool_node (decl);
751 if (node->finalized)
752 needed = false;
753 else if (node->alias)
754 needed = false;
755 else if (!cgraph_global_info_ready
756 && (TREE_USED (decl)
757 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
758 /* needed */;
759 else if (node->needed)
760 /* needed */;
761 else if (DECL_COMDAT (decl))
762 needed = false;
763 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
764 && (optimize || !flag_keep_static_consts
765 || DECL_ARTIFICIAL (decl)))
766 needed = false;
768 if (needed)
770 rest_of_decl_compilation (decl, 1, 1);
771 return true;
775 return false;
778 /* Do any final processing required for the declarations in VEC, of
779 which there are LEN. We write out inline functions and variables
780 that have been deferred until this point, but which are required.
781 Returns nonzero if anything was put out. */
783 bool
784 wrapup_global_declarations (tree *vec, int len)
786 bool reconsider, output_something = false;
787 int i;
789 for (i = 0; i < len; i++)
790 wrapup_global_declaration_1 (vec[i]);
792 /* Now emit any global variables or functions that we have been
793 putting off. We need to loop in case one of the things emitted
794 here references another one which comes earlier in the list. */
797 reconsider = false;
798 for (i = 0; i < len; i++)
799 reconsider |= wrapup_global_declaration_2 (vec[i]);
800 if (reconsider)
801 output_something = true;
803 while (reconsider);
805 return output_something;
808 /* A subroutine of check_global_declarations. Issue appropriate warnings
809 for the global declaration DECL. */
811 void
812 check_global_declaration_1 (tree decl)
814 /* Warn about any function declared static but not defined. We don't
815 warn about variables, because many programs have static variables
816 that exist only to get some text into the object file. */
817 if (TREE_CODE (decl) == FUNCTION_DECL
818 && DECL_INITIAL (decl) == 0
819 && DECL_EXTERNAL (decl)
820 && ! DECL_ARTIFICIAL (decl)
821 && ! TREE_NO_WARNING (decl)
822 && ! TREE_PUBLIC (decl)
823 && (warn_unused_function
824 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
826 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
827 pedwarn (input_location, 0, "%q+F used but never defined", decl);
828 else
829 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
830 /* This symbol is effectively an "extern" declaration now. */
831 TREE_PUBLIC (decl) = 1;
832 assemble_external (decl);
835 /* Warn about static fns or vars defined but not used. */
836 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
837 /* We don't warn about "static const" variables because the
838 "rcs_id" idiom uses that construction. */
839 || (warn_unused_variable
840 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
841 && ! DECL_IN_SYSTEM_HEADER (decl)
842 && ! TREE_USED (decl)
843 /* The TREE_USED bit for file-scope decls is kept in the identifier,
844 to handle multiple external decls in different scopes. */
845 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
846 && ! DECL_EXTERNAL (decl)
847 && ! TREE_PUBLIC (decl)
848 /* A volatile variable might be used in some non-obvious way. */
849 && ! TREE_THIS_VOLATILE (decl)
850 /* Global register variables must be declared to reserve them. */
851 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
852 /* Otherwise, ask the language. */
853 && lang_hooks.decls.warn_unused_global (decl))
854 warning ((TREE_CODE (decl) == FUNCTION_DECL)
855 ? OPT_Wunused_function
856 : OPT_Wunused_variable,
857 "%q+D defined but not used", decl);
860 /* Issue appropriate warnings for the global declarations in VEC (of
861 which there are LEN). */
863 void
864 check_global_declarations (tree *vec, int len)
866 int i;
868 for (i = 0; i < len; i++)
869 check_global_declaration_1 (vec[i]);
872 /* Emit debugging information for all global declarations in VEC. */
874 void
875 emit_debug_global_declarations (tree *vec, int len)
877 int i;
879 /* Avoid confusing the debug information machinery when there are errors. */
880 if (errorcount != 0 || sorrycount != 0)
881 return;
883 timevar_push (TV_SYMOUT);
884 for (i = 0; i < len; i++)
885 debug_hooks->global_decl (vec[i]);
886 timevar_pop (TV_SYMOUT);
889 /* Warn about a use of an identifier which was marked deprecated. */
890 void
891 warn_deprecated_use (tree node)
893 if (node == 0 || !warn_deprecated_decl)
894 return;
896 if (DECL_P (node))
898 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
899 warning (OPT_Wdeprecated_declarations,
900 "%qD is deprecated (declared at %s:%d)",
901 node, xloc.file, xloc.line);
903 else if (TYPE_P (node))
905 const char *what = NULL;
906 tree decl = TYPE_STUB_DECL (node);
908 if (TYPE_NAME (node))
910 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
911 what = IDENTIFIER_POINTER (TYPE_NAME (node));
912 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
913 && DECL_NAME (TYPE_NAME (node)))
914 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
917 if (decl)
919 expanded_location xloc
920 = expand_location (DECL_SOURCE_LOCATION (decl));
921 if (what)
922 warning (OPT_Wdeprecated_declarations,
923 "%qs is deprecated (declared at %s:%d)", what,
924 xloc.file, xloc.line);
925 else
926 warning (OPT_Wdeprecated_declarations,
927 "type is deprecated (declared at %s:%d)",
928 xloc.file, xloc.line);
930 else
932 if (what)
933 warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
934 else
935 warning (OPT_Wdeprecated_declarations, "type is deprecated");
940 /* Compile an entire translation unit. Write a file of assembly
941 output and various debugging dumps. */
943 static void
944 compile_file (void)
946 /* Initialize yet another pass. */
948 ggc_protect_identifiers = true;
950 init_cgraph ();
951 init_final (main_input_filename);
952 coverage_init (aux_base_name);
953 statistics_init ();
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)
966 return;
968 ggc_protect_identifiers = false;
970 lang_hooks.decls.final_write_globals ();
972 if (errorcount || sorrycount)
973 return;
975 varpool_assemble_pending_decls ();
976 finish_aliases_2 ();
978 /* This must occur after the loop to output deferred functions.
979 Else the coverage initializer would not be emitted if all the
980 functions in this compilation unit were deferred. */
981 coverage_finish ();
983 /* Likewise for mudflap static object registrations. */
984 if (flag_mudflap)
985 mudflap_finish_file ();
987 /* Likewise for emulated thread-local storage. */
988 if (!targetm.have_tls)
989 emutls_finish ();
991 output_shared_constant_pool ();
992 output_object_blocks ();
994 /* Write out any pending weak symbol declarations. */
995 weak_finish ();
997 /* Do dbx symbols. */
998 timevar_push (TV_SYMOUT);
1000 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1001 if (dwarf2out_do_frame ())
1002 dwarf2out_frame_finish ();
1003 #endif
1005 (*debug_hooks->finish) (main_input_filename);
1006 timevar_pop (TV_SYMOUT);
1008 /* Output some stuff at end of file if nec. */
1010 dw2_output_indirect_constants ();
1012 /* Flush any pending external directives. */
1013 process_pending_assemble_externals ();
1015 /* Attach a special .ident directive to the end of the file to identify
1016 the version of GCC which compiled this code. The format of the .ident
1017 string is patterned after the ones produced by native SVR4 compilers. */
1018 #ifdef IDENT_ASM_OP
1019 if (!flag_no_ident)
1021 const char *pkg_version = "(GNU) ";
1023 if (strcmp ("(GCC) ", pkgversion_string))
1024 pkg_version = pkgversion_string;
1025 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1026 IDENT_ASM_OP, pkg_version, version_string);
1028 #endif
1030 /* This must be at the end. Some target ports emit end of file directives
1031 into the assembly file here, and hence we can not output anything to the
1032 assembly file after this point. */
1033 targetm.asm_out.file_end ();
1036 /* Parse a -d... command line switch. */
1038 void
1039 decode_d_option (const char *arg)
1041 int c;
1043 while (*arg)
1044 switch (c = *arg++)
1046 case 'A':
1047 flag_debug_asm = 1;
1048 break;
1049 case 'p':
1050 flag_print_asm_name = 1;
1051 break;
1052 case 'P':
1053 flag_dump_rtl_in_asm = 1;
1054 flag_print_asm_name = 1;
1055 break;
1056 case 'v':
1057 graph_dump_format = vcg;
1058 break;
1059 case 'x':
1060 rtl_dump_and_exit = 1;
1061 break;
1062 case 'y':
1063 set_yydebug = 1;
1064 break;
1065 case 'D': /* These are handled by the preprocessor. */
1066 case 'I':
1067 case 'M':
1068 case 'N':
1069 case 'U':
1070 break;
1071 case 'H':
1072 setup_core_dumping();
1073 break;
1074 case 'a':
1075 enable_rtl_dump_file ();
1076 break;
1078 default:
1079 warning (0, "unrecognized gcc debugging option: %c", c);
1080 break;
1084 /* Indexed by enum debug_info_type. */
1085 const char *const debug_type_names[] =
1087 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1090 /* Print version information to FILE.
1091 Each line begins with INDENT (for the case where FILE is the
1092 assembler output file). */
1094 void
1095 print_version (FILE *file, const char *indent)
1097 static const char fmt1[] =
1098 #ifdef __GNUC__
1099 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1100 #else
1101 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1102 #endif
1104 static const char fmt2[] =
1105 N_("GMP version %s, MPFR version %s.\n");
1106 static const char fmt3[] =
1107 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1108 static const char fmt4[] =
1109 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1110 #ifndef __VERSION__
1111 #define __VERSION__ "[?]"
1112 #endif
1113 fprintf (file,
1114 file == stderr ? _(fmt1) : fmt1,
1115 indent, *indent != 0 ? " " : "",
1116 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1117 indent, __VERSION__);
1119 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1120 two string formats, "i.j.k" and "i.j" when k is zero. */
1121 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1122 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1123 #if __GNU_MP_VERSION_PATCHLEVEL == 0
1124 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1125 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1126 #else
1127 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1128 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1129 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1130 #endif
1131 fprintf (file,
1132 file == stderr ? _(fmt2) : fmt2,
1133 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING);
1134 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1135 fprintf (file,
1136 file == stderr ? _(fmt3) : fmt3,
1137 indent, *indent != 0 ? " " : "",
1138 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1139 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1140 fprintf (file,
1141 file == stderr ? _(fmt3) : fmt3,
1142 indent, *indent != 0 ? " " : "",
1143 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1144 fprintf (file,
1145 file == stderr ? _(fmt4) : fmt4,
1146 indent, *indent != 0 ? " " : "",
1147 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1150 #ifdef ASM_COMMENT_START
1151 static int
1152 print_to_asm_out_file (print_switch_type type, const char * text)
1154 bool prepend_sep = true;
1156 switch (type)
1158 case SWITCH_TYPE_LINE_END:
1159 putc ('\n', asm_out_file);
1160 return 1;
1162 case SWITCH_TYPE_LINE_START:
1163 fputs (ASM_COMMENT_START, asm_out_file);
1164 return strlen (ASM_COMMENT_START);
1166 case SWITCH_TYPE_DESCRIPTIVE:
1167 if (ASM_COMMENT_START[0] == 0)
1168 prepend_sep = false;
1169 /* Drop through. */
1170 case SWITCH_TYPE_PASSED:
1171 case SWITCH_TYPE_ENABLED:
1172 if (prepend_sep)
1173 fputc (' ', asm_out_file);
1174 fprintf (asm_out_file, text);
1175 /* No need to return the length here as
1176 print_single_switch has already done it. */
1177 return 0;
1179 default:
1180 return -1;
1183 #endif
1185 static int
1186 print_to_stderr (print_switch_type type, const char * text)
1188 switch (type)
1190 case SWITCH_TYPE_LINE_END:
1191 putc ('\n', stderr);
1192 return 1;
1194 case SWITCH_TYPE_LINE_START:
1195 return 0;
1197 case SWITCH_TYPE_PASSED:
1198 case SWITCH_TYPE_ENABLED:
1199 fputc (' ', stderr);
1200 /* Drop through. */
1202 case SWITCH_TYPE_DESCRIPTIVE:
1203 fprintf (stderr, text);
1204 /* No need to return the length here as
1205 print_single_switch has already done it. */
1206 return 0;
1208 default:
1209 return -1;
1213 /* Print an option value and return the adjusted position in the line.
1214 ??? print_fn doesn't handle errors, eg disk full; presumably other
1215 code will catch a disk full though. */
1217 static int
1218 print_single_switch (print_switch_fn_type print_fn,
1219 int pos,
1220 print_switch_type type,
1221 const char * text)
1223 /* The ultrix fprintf returns 0 on success, so compute the result
1224 we want here since we need it for the following test. The +1
1225 is for the separator character that will probably be emitted. */
1226 int len = strlen (text) + 1;
1228 if (pos != 0
1229 && pos + len > MAX_LINE)
1231 print_fn (SWITCH_TYPE_LINE_END, NULL);
1232 pos = 0;
1235 if (pos == 0)
1236 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1238 print_fn (type, text);
1239 return pos + len;
1242 /* Print active target switches using PRINT_FN.
1243 POS is the current cursor position and MAX is the size of a "line".
1244 Each line begins with INDENT and ends with TERM.
1245 Each switch is separated from the next by SEP. */
1247 static void
1248 print_switch_values (print_switch_fn_type print_fn)
1250 int pos = 0;
1251 size_t j;
1252 const char **p;
1254 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1255 that it can be printed below. This helps reproducibility. */
1256 if (!flag_random_seed)
1257 init_random_seed ();
1259 /* Print the options as passed. */
1260 pos = print_single_switch (print_fn, pos,
1261 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1263 for (p = &save_argv[1]; *p != NULL; p++)
1265 if (**p == '-')
1267 /* Ignore these. */
1268 if (strcmp (*p, "-o") == 0
1269 || strcmp (*p, "-dumpbase") == 0
1270 || strcmp (*p, "-auxbase") == 0)
1272 if (p[1] != NULL)
1273 p++;
1274 continue;
1277 if (strcmp (*p, "-quiet") == 0
1278 || strcmp (*p, "-version") == 0)
1279 continue;
1281 if ((*p)[1] == 'd')
1282 continue;
1285 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1288 if (pos > 0)
1289 print_fn (SWITCH_TYPE_LINE_END, NULL);
1291 /* Print the -f and -m options that have been enabled.
1292 We don't handle language specific options but printing argv
1293 should suffice. */
1294 pos = print_single_switch (print_fn, 0,
1295 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1297 for (j = 0; j < cl_options_count; j++)
1298 if ((cl_options[j].flags & CL_REPORT)
1299 && option_enabled (j) > 0)
1300 pos = print_single_switch (print_fn, pos,
1301 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1303 print_fn (SWITCH_TYPE_LINE_END, NULL);
1306 /* Open assembly code output file. Do this even if -fsyntax-only is
1307 on, because then the driver will have provided the name of a
1308 temporary file or bit bucket for us. NAME is the file specified on
1309 the command line, possibly NULL. */
1310 static void
1311 init_asm_output (const char *name)
1313 if (name == NULL && asm_file_name == 0)
1314 asm_out_file = stdout;
1315 else
1317 if (asm_file_name == 0)
1319 int len = strlen (dump_base_name);
1320 char *dumpname = XNEWVEC (char, len + 6);
1322 memcpy (dumpname, dump_base_name, len + 1);
1323 strip_off_ending (dumpname, len);
1324 strcat (dumpname, ".s");
1325 asm_file_name = dumpname;
1327 if (!strcmp (asm_file_name, "-"))
1328 asm_out_file = stdout;
1329 else
1330 asm_out_file = fopen (asm_file_name, "w+b");
1331 if (asm_out_file == 0)
1332 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1335 if (!flag_syntax_only)
1337 targetm.asm_out.file_start ();
1339 if (flag_record_gcc_switches)
1341 if (targetm.asm_out.record_gcc_switches)
1343 /* Let the target know that we are about to start recording. */
1344 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1345 NULL);
1346 /* Now record the switches. */
1347 print_switch_values (targetm.asm_out.record_gcc_switches);
1348 /* Let the target know that the recording is over. */
1349 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1350 NULL);
1352 else
1353 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1356 #ifdef ASM_COMMENT_START
1357 if (flag_verbose_asm)
1359 /* Print the list of switches in effect
1360 into the assembler file as comments. */
1361 print_version (asm_out_file, ASM_COMMENT_START);
1362 print_switch_values (print_to_asm_out_file);
1363 fprintf (asm_out_file, "\n");
1365 #endif
1369 /* Return true if the state of option OPTION should be stored in PCH files
1370 and checked by default_pch_valid_p. Store the option's current state
1371 in STATE if so. */
1373 static inline bool
1374 option_affects_pch_p (int option, struct cl_option_state *state)
1376 if ((cl_options[option].flags & CL_TARGET) == 0)
1377 return false;
1378 if (cl_options[option].flag_var == &target_flags)
1379 if (targetm.check_pch_target_flags)
1380 return false;
1381 return get_option_state (option, state);
1384 /* Default version of get_pch_validity.
1385 By default, every flag difference is fatal; that will be mostly right for
1386 most targets, but completely right for very few. */
1388 void *
1389 default_get_pch_validity (size_t *len)
1391 struct cl_option_state state;
1392 size_t i;
1393 char *result, *r;
1395 *len = 2;
1396 if (targetm.check_pch_target_flags)
1397 *len += sizeof (target_flags);
1398 for (i = 0; i < cl_options_count; i++)
1399 if (option_affects_pch_p (i, &state))
1400 *len += state.size;
1402 result = r = XNEWVEC (char, *len);
1403 r[0] = flag_pic;
1404 r[1] = flag_pie;
1405 r += 2;
1406 if (targetm.check_pch_target_flags)
1408 memcpy (r, &target_flags, sizeof (target_flags));
1409 r += sizeof (target_flags);
1412 for (i = 0; i < cl_options_count; i++)
1413 if (option_affects_pch_p (i, &state))
1415 memcpy (r, state.data, state.size);
1416 r += state.size;
1419 return result;
1422 /* Return a message which says that a PCH file was created with a different
1423 setting of OPTION. */
1425 static const char *
1426 pch_option_mismatch (const char *option)
1428 char *r;
1430 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1431 if (r == NULL)
1432 return _("out of memory");
1433 return r;
1436 /* Default version of pch_valid_p. */
1438 const char *
1439 default_pch_valid_p (const void *data_p, size_t len)
1441 struct cl_option_state state;
1442 const char *data = (const char *)data_p;
1443 size_t i;
1445 /* -fpic and -fpie also usually make a PCH invalid. */
1446 if (data[0] != flag_pic)
1447 return _("created and used with different settings of -fpic");
1448 if (data[1] != flag_pie)
1449 return _("created and used with different settings of -fpie");
1450 data += 2;
1452 /* Check target_flags. */
1453 if (targetm.check_pch_target_flags)
1455 int tf;
1456 const char *r;
1458 memcpy (&tf, data, sizeof (target_flags));
1459 data += sizeof (target_flags);
1460 len -= sizeof (target_flags);
1461 r = targetm.check_pch_target_flags (tf);
1462 if (r != NULL)
1463 return r;
1466 for (i = 0; i < cl_options_count; i++)
1467 if (option_affects_pch_p (i, &state))
1469 if (memcmp (data, state.data, state.size) != 0)
1470 return pch_option_mismatch (cl_options[i].opt_text);
1471 data += state.size;
1472 len -= state.size;
1475 return NULL;
1478 /* Default tree printer. Handles declarations only. */
1479 static bool
1480 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1481 int precision, bool wide, bool set_locus, bool hash)
1483 tree t;
1485 /* FUTURE: %+x should set the locus. */
1486 if (precision != 0 || wide || hash)
1487 return false;
1489 switch (*spec)
1491 case 'D':
1492 t = va_arg (*text->args_ptr, tree);
1493 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1494 t = DECL_DEBUG_EXPR (t);
1495 break;
1497 case 'F':
1498 case 'T':
1499 t = va_arg (*text->args_ptr, tree);
1500 break;
1502 default:
1503 return false;
1506 if (set_locus && text->locus)
1507 *text->locus = DECL_SOURCE_LOCATION (t);
1509 if (DECL_P (t))
1511 const char *n = DECL_NAME (t)
1512 ? lang_hooks.decl_printable_name (t, 2)
1513 : "<anonymous>";
1514 pp_string (pp, n);
1516 else
1517 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1519 return true;
1522 /* A helper function; used as the reallocator function for cpp's line
1523 table. */
1524 static void *
1525 realloc_for_line_map (void *ptr, size_t len)
1527 return ggc_realloc (ptr, len);
1530 /* Initialization of the front end environment, before command line
1531 options are parsed. Signal handlers, internationalization etc.
1532 ARGV0 is main's argv[0]. */
1533 static void
1534 general_init (const char *argv0)
1536 const char *p;
1538 p = argv0 + strlen (argv0);
1539 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1540 --p;
1541 progname = p;
1543 xmalloc_set_program_name (progname);
1545 hex_init ();
1547 /* Unlock the stdio streams. */
1548 unlock_std_streams ();
1550 gcc_init_libintl ();
1552 /* Initialize the diagnostics reporting machinery, so option parsing
1553 can give warnings and errors. */
1554 diagnostic_initialize (global_dc);
1555 /* Set a default printer. Language specific initializations will
1556 override it later. */
1557 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1559 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1560 #ifdef SIGSEGV
1561 signal (SIGSEGV, crash_signal);
1562 #endif
1563 #ifdef SIGILL
1564 signal (SIGILL, crash_signal);
1565 #endif
1566 #ifdef SIGBUS
1567 signal (SIGBUS, crash_signal);
1568 #endif
1569 #ifdef SIGABRT
1570 signal (SIGABRT, crash_signal);
1571 #endif
1572 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1573 signal (SIGIOT, crash_signal);
1574 #endif
1575 #ifdef SIGFPE
1576 signal (SIGFPE, crash_signal);
1577 #endif
1579 /* Other host-specific signal setup. */
1580 (*host_hooks.extra_signals)();
1582 /* Initialize the garbage-collector, string pools and tree type hash
1583 table. */
1584 init_ggc ();
1585 init_stringpool ();
1586 line_table = GGC_NEW (struct line_maps);
1587 linemap_init (line_table);
1588 line_table->reallocator = realloc_for_line_map;
1589 init_ttree ();
1591 /* Initialize register usage now so switches may override. */
1592 init_reg_sets ();
1594 /* Register the language-independent parameters. */
1595 add_params (lang_independent_params, LAST_PARAM);
1597 /* This must be done after add_params but before argument processing. */
1598 init_ggc_heuristics();
1599 init_optimization_passes ();
1600 statistics_early_init ();
1603 /* Return true if the current target supports -fsection-anchors. */
1605 static bool
1606 target_supports_section_anchors_p (void)
1608 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1609 return false;
1611 if (targetm.asm_out.output_anchor == NULL)
1612 return false;
1614 return true;
1617 /* Default the align_* variables to 1 if they're still unset, and
1618 set up the align_*_log variables. */
1619 static void
1620 init_alignments (void)
1622 if (align_loops <= 0)
1623 align_loops = 1;
1624 if (align_loops_max_skip > align_loops)
1625 align_loops_max_skip = align_loops - 1;
1626 align_loops_log = floor_log2 (align_loops * 2 - 1);
1627 if (align_jumps <= 0)
1628 align_jumps = 1;
1629 if (align_jumps_max_skip > align_jumps)
1630 align_jumps_max_skip = align_jumps - 1;
1631 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1632 if (align_labels <= 0)
1633 align_labels = 1;
1634 align_labels_log = floor_log2 (align_labels * 2 - 1);
1635 if (align_labels_max_skip > align_labels)
1636 align_labels_max_skip = align_labels - 1;
1637 if (align_functions <= 0)
1638 align_functions = 1;
1639 align_functions_log = floor_log2 (align_functions * 2 - 1);
1642 /* Process the options that have been parsed. */
1643 static void
1644 process_options (void)
1646 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1647 This can happen with incorrect pre-processed input. */
1648 debug_hooks = &do_nothing_debug_hooks;
1650 /* This replaces set_Wunused. */
1651 if (warn_unused_function == -1)
1652 warn_unused_function = warn_unused;
1653 if (warn_unused_label == -1)
1654 warn_unused_label = warn_unused;
1655 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1656 if (warn_unused_parameter == -1)
1657 warn_unused_parameter = (warn_unused && extra_warnings);
1658 if (warn_unused_variable == -1)
1659 warn_unused_variable = warn_unused;
1660 if (warn_unused_value == -1)
1661 warn_unused_value = warn_unused;
1663 /* Allow the front end to perform consistency checks and do further
1664 initialization based on the command line options. This hook also
1665 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1666 so we can correctly initialize debug output. */
1667 no_backend = lang_hooks.post_options (&main_input_filename);
1669 #ifdef OVERRIDE_OPTIONS
1670 /* Some machines may reject certain combinations of options. */
1671 OVERRIDE_OPTIONS;
1672 #endif
1674 if (flag_section_anchors && !target_supports_section_anchors_p ())
1676 warning (OPT_fsection_anchors,
1677 "this target does not support %qs", "-fsection-anchors");
1678 flag_section_anchors = 0;
1681 if (flag_short_enums == 2)
1682 flag_short_enums = targetm.default_short_enums ();
1684 /* Set aux_base_name if not already set. */
1685 if (aux_base_name)
1687 else if (main_input_filename)
1689 char *name = xstrdup (lbasename (main_input_filename));
1691 strip_off_ending (name, strlen (name));
1692 aux_base_name = name;
1694 else
1695 aux_base_name = "gccaux";
1697 /* Unrolling all loops implies that standard loop unrolling must also
1698 be done. */
1699 if (flag_unroll_all_loops)
1700 flag_unroll_loops = 1;
1702 /* The loop unrolling code assumes that cse will be run after loop.
1703 web and rename-registers also help when run after loop unrolling. */
1705 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1706 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1707 if (flag_web == AUTODETECT_VALUE)
1708 flag_web = flag_unroll_loops || flag_peel_loops;
1709 if (flag_rename_registers == AUTODETECT_VALUE)
1710 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1712 if (flag_non_call_exceptions)
1713 flag_asynchronous_unwind_tables = 1;
1714 if (flag_asynchronous_unwind_tables)
1715 flag_unwind_tables = 1;
1717 if (flag_value_profile_transformations)
1718 flag_profile_values = 1;
1720 /* Warn about options that are not supported on this machine. */
1721 #ifndef INSN_SCHEDULING
1722 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1723 warning (0, "instruction scheduling not supported on this target machine");
1724 #endif
1725 #ifndef DELAY_SLOTS
1726 if (flag_delayed_branch)
1727 warning (0, "this target machine does not have delayed branches");
1728 #endif
1730 user_label_prefix = USER_LABEL_PREFIX;
1731 if (flag_leading_underscore != -1)
1733 /* If the default prefix is more complicated than "" or "_",
1734 issue a warning and ignore this option. */
1735 if (user_label_prefix[0] == 0 ||
1736 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1738 user_label_prefix = flag_leading_underscore ? "_" : "";
1740 else
1741 warning (0, "-f%sleading-underscore not supported on this target machine",
1742 flag_leading_underscore ? "" : "no-");
1745 /* If we are in verbose mode, write out the version and maybe all the
1746 option flags in use. */
1747 if (version_flag)
1749 print_version (stderr, "");
1750 if (! quiet_flag)
1751 print_switch_values (print_to_stderr);
1754 if (flag_syntax_only)
1756 write_symbols = NO_DEBUG;
1757 profile_flag = 0;
1760 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1761 level is 0. */
1762 if (debug_info_level == DINFO_LEVEL_NONE)
1763 write_symbols = NO_DEBUG;
1765 /* Now we know write_symbols, set up the debug hooks based on it.
1766 By default we do nothing for debug output. */
1767 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1768 default_debug_hooks = &do_nothing_debug_hooks;
1769 #if defined(DBX_DEBUGGING_INFO)
1770 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1771 default_debug_hooks = &dbx_debug_hooks;
1772 #endif
1773 #if defined(XCOFF_DEBUGGING_INFO)
1774 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1775 default_debug_hooks = &xcoff_debug_hooks;
1776 #endif
1777 #ifdef SDB_DEBUGGING_INFO
1778 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1779 default_debug_hooks = &sdb_debug_hooks;
1780 #endif
1781 #ifdef DWARF2_DEBUGGING_INFO
1782 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1783 default_debug_hooks = &dwarf2_debug_hooks;
1784 #endif
1785 #ifdef VMS_DEBUGGING_INFO
1786 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1787 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1788 default_debug_hooks = &vmsdbg_debug_hooks;
1789 #endif
1791 if (write_symbols == NO_DEBUG)
1793 #if defined(DBX_DEBUGGING_INFO)
1794 else if (write_symbols == DBX_DEBUG)
1795 debug_hooks = &dbx_debug_hooks;
1796 #endif
1797 #if defined(XCOFF_DEBUGGING_INFO)
1798 else if (write_symbols == XCOFF_DEBUG)
1799 debug_hooks = &xcoff_debug_hooks;
1800 #endif
1801 #ifdef SDB_DEBUGGING_INFO
1802 else if (write_symbols == SDB_DEBUG)
1803 debug_hooks = &sdb_debug_hooks;
1804 #endif
1805 #ifdef DWARF2_DEBUGGING_INFO
1806 else if (write_symbols == DWARF2_DEBUG)
1807 debug_hooks = &dwarf2_debug_hooks;
1808 #endif
1809 #ifdef VMS_DEBUGGING_INFO
1810 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1811 debug_hooks = &vmsdbg_debug_hooks;
1812 #endif
1813 else
1814 error ("target system does not support the \"%s\" debug format",
1815 debug_type_names[write_symbols]);
1817 /* Now we know which debug output will be used so we can set
1818 flag_var_tracking, flag_rename_registers if the user has
1819 not specified them. */
1820 if (debug_info_level < DINFO_LEVEL_NORMAL
1821 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1823 if (flag_var_tracking == 1
1824 || flag_var_tracking_uninit == 1)
1826 if (debug_info_level < DINFO_LEVEL_NORMAL)
1827 warning (0, "variable tracking requested, but useless unless "
1828 "producing debug info");
1829 else
1830 warning (0, "variable tracking requested, but not supported "
1831 "by this debug format");
1833 flag_var_tracking = 0;
1834 flag_var_tracking_uninit = 0;
1837 if (flag_rename_registers == AUTODETECT_VALUE)
1838 flag_rename_registers = default_debug_hooks->var_location
1839 != do_nothing_debug_hooks.var_location;
1841 if (flag_var_tracking == AUTODETECT_VALUE)
1842 flag_var_tracking = optimize >= 1;
1844 if (flag_tree_cselim == AUTODETECT_VALUE)
1845 #ifdef HAVE_conditional_move
1846 flag_tree_cselim = 1;
1847 #else
1848 flag_tree_cselim = 0;
1849 #endif
1851 /* If the user specifically requested variable tracking with tagging
1852 uninitialized variables, we need to turn on variable tracking.
1853 (We already determined above that variable tracking is feasible.) */
1854 if (flag_var_tracking_uninit)
1855 flag_var_tracking = 1;
1857 /* If auxiliary info generation is desired, open the output file.
1858 This goes in the same directory as the source file--unlike
1859 all the other output files. */
1860 if (flag_gen_aux_info)
1862 aux_info_file = fopen (aux_info_file_name, "w");
1863 if (aux_info_file == 0)
1864 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1867 if (! targetm.have_named_sections)
1869 if (flag_function_sections)
1871 warning (0, "-ffunction-sections not supported for this target");
1872 flag_function_sections = 0;
1874 if (flag_data_sections)
1876 warning (0, "-fdata-sections not supported for this target");
1877 flag_data_sections = 0;
1881 if (flag_function_sections && profile_flag)
1883 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1884 flag_function_sections = 0;
1887 #ifndef HAVE_prefetch
1888 if (flag_prefetch_loop_arrays)
1890 warning (0, "-fprefetch-loop-arrays not supported for this target");
1891 flag_prefetch_loop_arrays = 0;
1893 #else
1894 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1896 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1897 flag_prefetch_loop_arrays = 0;
1899 #endif
1901 /* This combination of options isn't handled for i386 targets and doesn't
1902 make much sense anyway, so don't allow it. */
1903 if (flag_prefetch_loop_arrays && optimize_size)
1905 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1906 flag_prefetch_loop_arrays = 0;
1909 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1910 if (flag_signaling_nans)
1911 flag_trapping_math = 1;
1913 /* We cannot reassociate if we want traps or signed zeros.  */
1914 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1916 warning (0, "-fassociative-math disabled; other options take precedence");
1917 flag_associative_math = 0;
1920 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1921 if (flag_cx_limited_range)
1922 flag_complex_method = 0;
1924 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1925 if (flag_cx_fortran_rules)
1926 flag_complex_method = 1;
1928 /* Targets must be able to place spill slots at lower addresses. If the
1929 target already uses a soft frame pointer, the transition is trivial. */
1930 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1932 warning (0, "-fstack-protector not supported for this target");
1933 flag_stack_protect = 0;
1935 if (!flag_stack_protect)
1936 warn_stack_protect = 0;
1938 /* ??? Unwind info is not correct around the CFG unless either a frame
1939 pointer is present or A_O_A is set. Fixing this requires rewriting
1940 unwind info generation to be aware of the CFG and propagating states
1941 around edges. */
1942 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1943 && flag_omit_frame_pointer)
1945 warning (0, "unwind tables currently require a frame pointer "
1946 "for correctness");
1947 flag_omit_frame_pointer = 0;
1951 /* This function can be called multiple times to reinitialize the compiler
1952 back end when register classes or instruction sets have changed,
1953 before each function. */
1954 static void
1955 backend_init_target (void)
1957 /* Initialize alignment variables. */
1958 init_alignments ();
1960 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1961 to initialize reg_raw_mode[]. */
1962 init_emit_regs ();
1964 /* This invokes target hooks to set fixed_reg[] etc, which is
1965 mode-dependent. */
1966 init_regs ();
1968 /* This depends on stack_pointer_rtx. */
1969 init_fake_stack_mems ();
1971 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1972 mode-dependent. */
1973 init_alias_target ();
1975 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1976 init_reload ();
1978 /* The following initialization functions need to generate rtl, so
1979 provide a dummy function context for them. */
1980 init_dummy_function_start ();
1982 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1983 on a mode change. */
1984 init_expmed ();
1986 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1987 after a mode change as well. */
1988 if (flag_caller_saves)
1989 init_caller_save ();
1990 expand_dummy_function_end ();
1993 /* Initialize the compiler back end. This function is called only once,
1994 when starting the compiler. */
1995 static void
1996 backend_init (void)
1998 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1999 || debug_info_level == DINFO_LEVEL_VERBOSE
2000 #ifdef VMS_DEBUGGING_INFO
2001 /* Enable line number info for traceback. */
2002 || debug_info_level > DINFO_LEVEL_NONE
2003 #endif
2004 || flag_test_coverage);
2006 init_rtlanal ();
2007 init_inline_once ();
2008 init_varasm_once ();
2009 save_register_info ();
2011 /* Initialize the target-specific back end pieces. */
2012 backend_init_target ();
2015 /* Initialize things that are both lang-dependent and target-dependent.
2016 This function can be called more than once if target parameters change. */
2017 static void
2018 lang_dependent_init_target (void)
2020 /* This creates various _DECL nodes, so needs to be called after the
2021 front end is initialized. It also depends on the HAVE_xxx macros
2022 generated from the target machine description. */
2023 init_optabs ();
2025 /* The following initialization functions need to generate rtl, so
2026 provide a dummy function context for them. */
2027 init_dummy_function_start ();
2029 /* Do the target-specific parts of expr initialization. */
2030 init_expr_target ();
2032 /* Although the actions of init_set_costs are language-independent,
2033 it uses optabs, so we cannot call it from backend_init. */
2034 init_set_costs ();
2036 expand_dummy_function_end ();
2039 /* Language-dependent initialization. Returns nonzero on success. */
2040 static int
2041 lang_dependent_init (const char *name)
2043 location_t save_loc = input_location;
2044 if (dump_base_name == 0)
2045 dump_base_name = name && name[0] ? name : "gccdump";
2047 /* Other front-end initialization. */
2048 input_location = BUILTINS_LOCATION;
2049 if (lang_hooks.init () == 0)
2050 return 0;
2051 input_location = save_loc;
2053 init_asm_output (name);
2055 /* This creates various _DECL nodes, so needs to be called after the
2056 front end is initialized. */
2057 init_eh ();
2059 /* Do the target-specific parts of the initialization. */
2060 lang_dependent_init_target ();
2062 /* If dbx symbol table desired, initialize writing it and output the
2063 predefined types. */
2064 timevar_push (TV_SYMOUT);
2066 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2067 if (dwarf2out_do_frame ())
2068 dwarf2out_frame_init ();
2069 #endif
2071 /* Now we have the correct original filename, we can initialize
2072 debug output. */
2073 (*debug_hooks->init) (name);
2075 timevar_pop (TV_SYMOUT);
2077 return 1;
2081 /* Reinitialize everything when target parameters, such as register usage,
2082 have changed. */
2083 void
2084 target_reinit (void)
2086 /* Reinitialize RTL backend. */
2087 backend_init_target ();
2089 /* Reinitialize lang-dependent parts. */
2090 lang_dependent_init_target ();
2093 void
2094 dump_memory_report (bool final)
2096 ggc_print_statistics ();
2097 stringpool_statistics ();
2098 dump_tree_statistics ();
2099 dump_gimple_statistics ();
2100 dump_rtx_statistics ();
2101 dump_varray_statistics ();
2102 dump_alloc_pool_statistics ();
2103 dump_bitmap_statistics ();
2104 dump_ggc_loc_statistics (final);
2107 /* Clean up: close opened files, etc. */
2109 static void
2110 finalize (void)
2112 /* Close the dump files. */
2113 if (flag_gen_aux_info)
2115 fclose (aux_info_file);
2116 if (errorcount)
2117 unlink (aux_info_file_name);
2120 /* Close non-debugging input and output files. Take special care to note
2121 whether fclose returns an error, since the pages might still be on the
2122 buffer chain while the file is open. */
2124 if (asm_out_file)
2126 if (ferror (asm_out_file) != 0)
2127 fatal_error ("error writing to %s: %m", asm_file_name);
2128 if (fclose (asm_out_file) != 0)
2129 fatal_error ("error closing %s: %m", asm_file_name);
2132 statistics_fini ();
2133 finish_optimization_passes ();
2135 if (mem_report)
2136 dump_memory_report (true);
2138 /* Language-specific end of compilation actions. */
2139 lang_hooks.finish ();
2142 /* Initialize the compiler, and compile the input file. */
2143 static void
2144 do_compile (void)
2146 /* Initialize timing first. The C front ends read the main file in
2147 the post_options hook, and C++ does file timings. */
2148 if (time_report || !quiet_flag || flag_detailed_statistics)
2149 timevar_init ();
2150 timevar_start (TV_TOTAL);
2152 process_options ();
2154 /* Don't do any more if an error has already occurred. */
2155 if (!errorcount)
2157 /* This must be run always, because it is needed to compute the FP
2158 predefined macros, such as __LDBL_MAX__, for targets using non
2159 default FP formats. */
2160 init_adjust_machine_modes ();
2162 /* Set up the back-end if requested. */
2163 if (!no_backend)
2164 backend_init ();
2166 /* Language-dependent initialization. Returns true on success. */
2167 if (lang_dependent_init (main_input_filename))
2168 compile_file ();
2170 finalize ();
2173 /* Stop timing and print the times. */
2174 timevar_stop (TV_TOTAL);
2175 timevar_print (stderr);
2178 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2179 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2180 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2182 It is not safe to call this function more than once. */
2185 toplev_main (unsigned int argc, const char **argv)
2187 save_argv = argv;
2189 /* Initialization of GCC's environment, and diagnostics. */
2190 general_init (argv[0]);
2192 /* Parse the options and do minimal processing; basically just
2193 enough to default flags appropriately. */
2194 decode_options (argc, argv);
2196 init_local_tick ();
2198 /* Exit early if we can (e.g. -help). */
2199 if (!exit_after_options)
2200 do_compile ();
2202 if (warningcount || errorcount)
2203 print_ignored_options ();
2205 if (errorcount || sorrycount)
2206 return (FATAL_EXIT_CODE);
2208 return (SUCCESS_EXIT_CODE);