re PR bootstrap/45700 (--enable-checking=fold bootstrap failures)
[gcc.git] / gcc / toplev.c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
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. */
26
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include <signal.h>
32
33 #ifdef HAVE_SYS_TIMES_H
34 # include <sys/times.h>
35 #endif
36
37 #include "line-map.h"
38 #include "input.h"
39 #include "tree.h"
40 #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
41 #include "version.h"
42 #include "rtl.h"
43 #include "tm_p.h"
44 #include "flags.h"
45 #include "insn-attr.h"
46 #include "insn-config.h"
47 #include "insn-flags.h"
48 #include "hard-reg-set.h"
49 #include "recog.h"
50 #include "output.h"
51 #include "except.h"
52 #include "function.h"
53 #include "toplev.h"
54 #include "expr.h"
55 #include "basic-block.h"
56 #include "intl.h"
57 #include "ggc.h"
58 #include "graph.h"
59 #include "regs.h"
60 #include "timevar.h"
61 #include "diagnostic.h"
62 #include "tree-diagnostic.h"
63 #include "tree-pretty-print.h"
64 #include "params.h"
65 #include "reload.h"
66 #include "ira.h"
67 #include "dwarf2asm.h"
68 #include "integrate.h"
69 #include "debug.h"
70 #include "target.h"
71 #include "langhooks.h"
72 #include "cfglayout.h"
73 #include "cfgloop.h"
74 #include "hosthooks.h"
75 #include "cgraph.h"
76 #include "opts.h"
77 #include "opts-diagnostic.h"
78 #include "coverage.h"
79 #include "value-prof.h"
80 #include "alloc-pool.h"
81 #include "tree-mudflap.h"
82 #include "tree-pass.h"
83 #include "gimple.h"
84 #include "tree-ssa-alias.h"
85 #include "plugin.h"
86
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
89 #endif
90
91 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
92 #include "dbxout.h"
93 #endif
94
95 #ifdef SDB_DEBUGGING_INFO
96 #include "sdbout.h"
97 #endif
98
99 #ifdef XCOFF_DEBUGGING_INFO
100 #include "xcoffout.h" /* Needed for external data
101 declarations for e.g. AIX 4.x. */
102 #endif
103
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 (bool);
111
112 static void crash_signal (int) ATTRIBUTE_NORETURN;
113 static void compile_file (void);
114
115 /* True if we don't need a backend (e.g. preprocessing only). */
116 static bool no_backend;
117
118 /* Length of line when printing switch values. */
119 #define MAX_LINE 75
120
121 /* Decoded options, and number of such options. */
122 struct cl_decoded_option *save_decoded_options;
123 unsigned int save_decoded_options_count;
124
125 /* Name of top-level original source file (what was input to cpp).
126 This comes from the #-command at the beginning of the actual input.
127 If there isn't any there, then this is the cc1 input file name. */
128
129 const char *main_input_filename;
130
131 /* Pointer to base name in main_input_filename, with directories and a
132 single final extension removed, and the length of this base
133 name. */
134 const char *main_input_basename;
135 int main_input_baselength;
136
137 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
138 to optimize in process_options (). */
139 #define AUTODETECT_VALUE 2
140
141 /* Debug hooks - dependent upon command line options. */
142
143 const struct gcc_debug_hooks *debug_hooks;
144
145 /* True if this is the lto front end. This is used to disable
146 gimple generation and lowering passes that are normally run on the
147 output of a front end. These passes must be bypassed for lto since
148 they have already been done before the gimple was written. */
149
150 bool in_lto_p = false;
151
152 /* The FUNCTION_DECL for the function currently being compiled,
153 or 0 if between functions. */
154 tree current_function_decl;
155
156 /* Set to the FUNC_BEGIN label of the current function, or NULL
157 if none. */
158 const char * current_function_func_begin_label;
159
160 /* A random sequence of characters, unless overridden by user. */
161 static const char *flag_random_seed;
162
163 /* A local time stamp derived from the time of compilation. It will be
164 zero if the system cannot provide a time. It will be -1u, if the
165 user has specified a particular random seed. */
166 unsigned local_tick;
167
168 /* -f flags. */
169
170 /* Generate code for GNU or NeXT Objective-C runtime environment. */
171
172 #ifdef NEXT_OBJC_RUNTIME
173 int flag_next_runtime = 1;
174 #else
175 int flag_next_runtime = 0;
176 #endif
177
178 /* Nonzero means make permerror produce warnings instead of errors. */
179
180 int flag_permissive = 0;
181
182 /* When non-NULL, indicates that whenever space is allocated on the
183 stack, the resulting stack pointer must not pass this
184 address---that is, for stacks that grow downward, the stack pointer
185 must always be greater than or equal to this address; for stacks
186 that grow upward, the stack pointer must be less than this address.
187 At present, the rtx may be either a REG or a SYMBOL_REF, although
188 the support provided depends on the backend. */
189 rtx stack_limit_rtx;
190
191 /* Type of stack check. */
192 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
193
194 /* True if the user has tagged the function with the 'section'
195 attribute. */
196
197 bool user_defined_section_attribute = false;
198
199 struct target_flag_state default_target_flag_state;
200 #if SWITCHABLE_TARGET
201 struct target_flag_state *this_target_flag_state = &default_target_flag_state;
202 #else
203 #define this_target_flag_state (&default_target_flag_state)
204 #endif
205
206 typedef struct
207 {
208 const char *const string;
209 int *const variable;
210 const int on_value;
211 }
212 lang_independent_options;
213
214 /* The user symbol prefix after having resolved same. */
215 const char *user_label_prefix;
216
217 static const param_info lang_independent_params[] = {
218 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
219 { OPTION, DEFAULT, MIN, MAX, HELP },
220 #include "params.def"
221 #undef DEFPARAM
222 { NULL, 0, 0, 0, NULL }
223 };
224
225 /* Output files for assembler code (real compiler output)
226 and debugging dumps. */
227
228 FILE *asm_out_file;
229 FILE *aux_info_file;
230 FILE *stack_usage_file = NULL;
231 FILE *dump_file = NULL;
232 const char *dump_file_name;
233
234 /* The current working directory of a translation. It's generally the
235 directory from which compilation was initiated, but a preprocessed
236 file may specify the original directory in which it was
237 created. */
238
239 static const char *src_pwd;
240
241 /* Initialize src_pwd with the given string, and return true. If it
242 was already initialized, return false. As a special case, it may
243 be called with a NULL argument to test whether src_pwd has NOT been
244 initialized yet. */
245
246 bool
247 set_src_pwd (const char *pwd)
248 {
249 if (src_pwd)
250 {
251 if (strcmp (src_pwd, pwd) == 0)
252 return true;
253 else
254 return false;
255 }
256
257 src_pwd = xstrdup (pwd);
258 return true;
259 }
260
261 /* Return the directory from which the translation unit was initiated,
262 in case set_src_pwd() was not called before to assign it a
263 different value. */
264
265 const char *
266 get_src_pwd (void)
267 {
268 if (! src_pwd)
269 {
270 src_pwd = getpwd ();
271 if (!src_pwd)
272 src_pwd = ".";
273 }
274
275 return src_pwd;
276 }
277
278 /* Called when the start of a function definition is parsed,
279 this function prints on stderr the name of the function. */
280 void
281 announce_function (tree decl)
282 {
283 if (!quiet_flag)
284 {
285 if (rtl_dump_and_exit)
286 fprintf (stderr, "%s ",
287 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
288 else
289 fprintf (stderr, " %s",
290 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
291 fflush (stderr);
292 pp_needs_newline (global_dc->printer) = true;
293 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
294 }
295 }
296
297 /* Initialize local_tick with the time of day, or -1 if
298 flag_random_seed is set. */
299
300 static void
301 init_local_tick (void)
302 {
303 if (!flag_random_seed)
304 {
305 /* Get some more or less random data. */
306 #ifdef HAVE_GETTIMEOFDAY
307 {
308 struct timeval tv;
309
310 gettimeofday (&tv, NULL);
311 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
312 }
313 #else
314 {
315 time_t now = time (NULL);
316
317 if (now != (time_t)-1)
318 local_tick = (unsigned) now;
319 }
320 #endif
321 }
322 else
323 local_tick = -1;
324 }
325
326 /* Set up a default flag_random_seed and local_tick, unless the user
327 already specified one. Must be called after init_local_tick. */
328
329 static void
330 init_random_seed (void)
331 {
332 unsigned HOST_WIDE_INT value;
333 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
334
335 value = local_tick ^ getpid ();
336
337 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
338 flag_random_seed = random_seed;
339 }
340
341 /* Obtain the random_seed string. Unless NOINIT, initialize it if
342 it's not provided in the command line. */
343
344 const char *
345 get_random_seed (bool noinit)
346 {
347 if (!flag_random_seed && !noinit)
348 init_random_seed ();
349 return flag_random_seed;
350 }
351
352 /* Modify the random_seed string to VAL. Return its previous
353 value. */
354
355 const char *
356 set_random_seed (const char *val)
357 {
358 const char *old = flag_random_seed;
359 flag_random_seed = val;
360 return old;
361 }
362
363 #if GCC_VERSION < 3004
364
365 /* The functions clz_hwi, ctz_hwi, ffs_hwi, floor_log2 and exact_log2
366 are defined as inline functions in toplev.h if GCC_VERSION >= 3004.
367 The definitions here are used for older versions of gcc. */
368
369 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
370 If X is 0, return -1. */
371
372 int
373 floor_log2 (unsigned HOST_WIDE_INT x)
374 {
375 int t = 0;
376
377 if (x == 0)
378 return -1;
379
380 if (HOST_BITS_PER_WIDE_INT > 64)
381 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
382 t += 64;
383 if (HOST_BITS_PER_WIDE_INT > 32)
384 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
385 t += 32;
386 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
387 t += 16;
388 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
389 t += 8;
390 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
391 t += 4;
392 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
393 t += 2;
394 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
395 t += 1;
396
397 return t;
398 }
399
400 /* Return the logarithm of X, base 2, considering X unsigned,
401 if X is a power of 2. Otherwise, returns -1. */
402
403 int
404 exact_log2 (unsigned HOST_WIDE_INT x)
405 {
406 if (x != (x & -x))
407 return -1;
408 return floor_log2 (x);
409 }
410
411 /* Given X, an unsigned number, return the number of least significant bits
412 that are zero. When X == 0, the result is the word size. */
413
414 int
415 ctz_hwi (unsigned HOST_WIDE_INT x)
416 {
417 return x ? floor_log2 (x & -x) : HOST_BITS_PER_WIDE_INT;
418 }
419
420 /* Similarly for most significant bits. */
421
422 int
423 clz_hwi (unsigned HOST_WIDE_INT x)
424 {
425 return HOST_BITS_PER_WIDE_INT - 1 - floor_log2(x);
426 }
427
428 /* Similar to ctz_hwi, except that the least significant bit is numbered
429 starting from 1, and X == 0 yields 0. */
430
431 int
432 ffs_hwi (unsigned HOST_WIDE_INT x)
433 {
434 return 1 + floor_log2 (x & -x);
435 }
436
437 #endif /* GCC_VERSION < 3004 */
438
439 /* Handler for fatal signals, such as SIGSEGV. These are transformed
440 into ICE messages, which is much more user friendly. In case the
441 error printer crashes, reset the signal to prevent infinite recursion. */
442
443 static void
444 crash_signal (int signo)
445 {
446 signal (signo, SIG_DFL);
447
448 /* If we crashed while processing an ASM statement, then be a little more
449 graceful. It's most likely the user's fault. */
450 if (this_is_asm_operands)
451 {
452 output_operand_lossage ("unrecoverable error");
453 exit (FATAL_EXIT_CODE);
454 }
455
456 internal_error ("%s", strsignal (signo));
457 }
458
459 /* Output a quoted string. */
460
461 void
462 output_quoted_string (FILE *asm_file, const char *string)
463 {
464 #ifdef OUTPUT_QUOTED_STRING
465 OUTPUT_QUOTED_STRING (asm_file, string);
466 #else
467 char c;
468
469 putc ('\"', asm_file);
470 while ((c = *string++) != 0)
471 {
472 if (ISPRINT (c))
473 {
474 if (c == '\"' || c == '\\')
475 putc ('\\', asm_file);
476 putc (c, asm_file);
477 }
478 else
479 fprintf (asm_file, "\\%03o", (unsigned char) c);
480 }
481 putc ('\"', asm_file);
482 #endif
483 }
484
485 /* A subroutine of wrapup_global_declarations. We've come to the end of
486 the compilation unit. All deferred variables should be undeferred,
487 and all incomplete decls should be finalized. */
488
489 void
490 wrapup_global_declaration_1 (tree decl)
491 {
492 /* We're not deferring this any longer. Assignment is conditional to
493 avoid needlessly dirtying PCH pages. */
494 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
495 && DECL_DEFER_OUTPUT (decl) != 0)
496 DECL_DEFER_OUTPUT (decl) = 0;
497
498 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
499 lang_hooks.finish_incomplete_decl (decl);
500 }
501
502 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
503 needs to be output. Return true if it is output. */
504
505 bool
506 wrapup_global_declaration_2 (tree decl)
507 {
508 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
509 return false;
510
511 /* Don't write out static consts, unless we still need them.
512
513 We also keep static consts if not optimizing (for debugging),
514 unless the user specified -fno-keep-static-consts.
515 ??? They might be better written into the debug information.
516 This is possible when using DWARF.
517
518 A language processor that wants static constants to be always
519 written out (even if it is not used) is responsible for
520 calling rest_of_decl_compilation itself. E.g. the C front-end
521 calls rest_of_decl_compilation from finish_decl.
522 One motivation for this is that is conventional in some
523 environments to write things like:
524 static const char rcsid[] = "... version string ...";
525 intending to force the string to be in the executable.
526
527 A language processor that would prefer to have unneeded
528 static constants "optimized away" would just defer writing
529 them out until here. E.g. C++ does this, because static
530 constants are often defined in header files.
531
532 ??? A tempting alternative (for both C and C++) would be
533 to force a constant to be written if and only if it is
534 defined in a main file, as opposed to an include file. */
535
536 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
537 {
538 struct varpool_node *node;
539 bool needed = true;
540 node = varpool_get_node (decl);
541
542 if (!node && flag_ltrans)
543 needed = false;
544 else if (node && node->finalized)
545 needed = false;
546 else if (node && node->alias)
547 needed = false;
548 else if (!cgraph_global_info_ready
549 && (TREE_USED (decl)
550 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
551 /* needed */;
552 else if (node && node->needed)
553 /* needed */;
554 else if (DECL_COMDAT (decl))
555 needed = false;
556 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
557 && (optimize || !flag_keep_static_consts
558 || DECL_ARTIFICIAL (decl)))
559 needed = false;
560
561 if (needed)
562 {
563 rest_of_decl_compilation (decl, 1, 1);
564 return true;
565 }
566 }
567
568 return false;
569 }
570
571 /* Do any final processing required for the declarations in VEC, of
572 which there are LEN. We write out inline functions and variables
573 that have been deferred until this point, but which are required.
574 Returns nonzero if anything was put out. */
575
576 bool
577 wrapup_global_declarations (tree *vec, int len)
578 {
579 bool reconsider, output_something = false;
580 int i;
581
582 for (i = 0; i < len; i++)
583 wrapup_global_declaration_1 (vec[i]);
584
585 /* Now emit any global variables or functions that we have been
586 putting off. We need to loop in case one of the things emitted
587 here references another one which comes earlier in the list. */
588 do
589 {
590 reconsider = false;
591 for (i = 0; i < len; i++)
592 reconsider |= wrapup_global_declaration_2 (vec[i]);
593 if (reconsider)
594 output_something = true;
595 }
596 while (reconsider);
597
598 return output_something;
599 }
600
601 /* A subroutine of check_global_declarations. Issue appropriate warnings
602 for the global declaration DECL. */
603
604 void
605 check_global_declaration_1 (tree decl)
606 {
607 /* Warn about any function declared static but not defined. We don't
608 warn about variables, because many programs have static variables
609 that exist only to get some text into the object file. */
610 if (TREE_CODE (decl) == FUNCTION_DECL
611 && DECL_INITIAL (decl) == 0
612 && DECL_EXTERNAL (decl)
613 && ! DECL_ARTIFICIAL (decl)
614 && ! TREE_NO_WARNING (decl)
615 && ! TREE_PUBLIC (decl)
616 && (warn_unused_function
617 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
618 {
619 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
620 pedwarn (input_location, 0, "%q+F used but never defined", decl);
621 else
622 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
623 /* This symbol is effectively an "extern" declaration now. */
624 TREE_PUBLIC (decl) = 1;
625 assemble_external (decl);
626 }
627
628 /* Warn about static fns or vars defined but not used. */
629 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
630 /* We don't warn about "static const" variables because the
631 "rcs_id" idiom uses that construction. */
632 || (warn_unused_variable
633 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
634 && ! DECL_IN_SYSTEM_HEADER (decl)
635 && ! TREE_USED (decl)
636 /* The TREE_USED bit for file-scope decls is kept in the identifier,
637 to handle multiple external decls in different scopes. */
638 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
639 && ! DECL_EXTERNAL (decl)
640 && ! TREE_PUBLIC (decl)
641 /* A volatile variable might be used in some non-obvious way. */
642 && ! TREE_THIS_VOLATILE (decl)
643 /* Global register variables must be declared to reserve them. */
644 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
645 /* Otherwise, ask the language. */
646 && lang_hooks.decls.warn_unused_global (decl))
647 warning ((TREE_CODE (decl) == FUNCTION_DECL)
648 ? OPT_Wunused_function
649 : OPT_Wunused_variable,
650 "%q+D defined but not used", decl);
651 }
652
653 /* Issue appropriate warnings for the global declarations in VEC (of
654 which there are LEN). */
655
656 void
657 check_global_declarations (tree *vec, int len)
658 {
659 int i;
660
661 for (i = 0; i < len; i++)
662 check_global_declaration_1 (vec[i]);
663 }
664
665 /* Emit debugging information for all global declarations in VEC. */
666
667 void
668 emit_debug_global_declarations (tree *vec, int len)
669 {
670 int i;
671
672 /* Avoid confusing the debug information machinery when there are errors. */
673 if (seen_error ())
674 return;
675
676 timevar_push (TV_SYMOUT);
677 for (i = 0; i < len; i++)
678 debug_hooks->global_decl (vec[i]);
679 timevar_pop (TV_SYMOUT);
680 }
681
682 /* Warn about a use of an identifier which was marked deprecated. */
683 void
684 warn_deprecated_use (tree node, tree attr)
685 {
686 const char *msg;
687
688 if (node == 0 || !warn_deprecated_decl)
689 return;
690
691 if (!attr)
692 {
693 if (DECL_P (node))
694 attr = DECL_ATTRIBUTES (node);
695 else if (TYPE_P (node))
696 {
697 tree decl = TYPE_STUB_DECL (node);
698 if (decl)
699 attr = lookup_attribute ("deprecated",
700 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
701 }
702 }
703
704 if (attr)
705 attr = lookup_attribute ("deprecated", attr);
706
707 if (attr)
708 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
709 else
710 msg = NULL;
711
712 if (DECL_P (node))
713 {
714 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
715 if (msg)
716 warning (OPT_Wdeprecated_declarations,
717 "%qD is deprecated (declared at %s:%d): %s",
718 node, xloc.file, xloc.line, msg);
719 else
720 warning (OPT_Wdeprecated_declarations,
721 "%qD is deprecated (declared at %s:%d)",
722 node, xloc.file, xloc.line);
723 }
724 else if (TYPE_P (node))
725 {
726 tree what = NULL_TREE;
727 tree decl = TYPE_STUB_DECL (node);
728
729 if (TYPE_NAME (node))
730 {
731 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
732 what = TYPE_NAME (node);
733 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
734 && DECL_NAME (TYPE_NAME (node)))
735 what = DECL_NAME (TYPE_NAME (node));
736 }
737
738 if (decl)
739 {
740 expanded_location xloc
741 = expand_location (DECL_SOURCE_LOCATION (decl));
742 if (what)
743 {
744 if (msg)
745 warning (OPT_Wdeprecated_declarations,
746 "%qE is deprecated (declared at %s:%d): %s",
747 what, xloc.file, xloc.line, msg);
748 else
749 warning (OPT_Wdeprecated_declarations,
750 "%qE is deprecated (declared at %s:%d)", what,
751 xloc.file, xloc.line);
752 }
753 else
754 {
755 if (msg)
756 warning (OPT_Wdeprecated_declarations,
757 "type is deprecated (declared at %s:%d): %s",
758 xloc.file, xloc.line, msg);
759 else
760 warning (OPT_Wdeprecated_declarations,
761 "type is deprecated (declared at %s:%d)",
762 xloc.file, xloc.line);
763 }
764 }
765 else
766 {
767 if (what)
768 {
769 if (msg)
770 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
771 what, msg);
772 else
773 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
774 }
775 else
776 {
777 if (msg)
778 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
779 msg);
780 else
781 warning (OPT_Wdeprecated_declarations, "type is deprecated");
782 }
783 }
784 }
785 }
786
787 /* Compile an entire translation unit. Write a file of assembly
788 output and various debugging dumps. */
789
790 static void
791 compile_file (void)
792 {
793 /* Initialize yet another pass. */
794
795 ggc_protect_identifiers = true;
796
797 init_cgraph ();
798 init_final (main_input_filename);
799 coverage_init (aux_base_name);
800 statistics_init ();
801 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
802
803 timevar_push (TV_PARSE);
804
805 /* Call the parser, which parses the entire file (calling
806 rest_of_compilation for each function). */
807 lang_hooks.parse_file ();
808
809 /* Compilation is now finished except for writing
810 what's left of the symbol table output. */
811 timevar_pop (TV_PARSE);
812
813 if (flag_syntax_only || flag_wpa)
814 return;
815
816 ggc_protect_identifiers = false;
817
818 /* This must also call cgraph_finalize_compilation_unit. */
819 lang_hooks.decls.final_write_globals ();
820
821 if (seen_error ())
822 return;
823
824 varpool_assemble_pending_decls ();
825 finish_aliases_2 ();
826
827 /* Likewise for mudflap static object registrations. */
828 if (flag_mudflap)
829 mudflap_finish_file ();
830
831 output_shared_constant_pool ();
832 output_object_blocks ();
833
834 /* Write out any pending weak symbol declarations. */
835 weak_finish ();
836
837 /* This must be at the end before unwind and debug info.
838 Some target ports emit PIC setup thunks here. */
839 targetm.asm_out.code_end ();
840
841 /* Do dbx symbols. */
842 timevar_push (TV_SYMOUT);
843
844 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
845 if (dwarf2out_do_frame ())
846 dwarf2out_frame_finish ();
847 #endif
848
849 (*debug_hooks->finish) (main_input_filename);
850 timevar_pop (TV_SYMOUT);
851
852 /* Output some stuff at end of file if nec. */
853
854 dw2_output_indirect_constants ();
855
856 /* Flush any pending external directives. */
857 process_pending_assemble_externals ();
858
859 /* Emit LTO marker if LTO info has been previously emitted. This is
860 used by collect2 to determine whether an object file contains IL.
861 We used to emit an undefined reference here, but this produces
862 link errors if an object file with IL is stored into a shared
863 library without invoking lto1. */
864 if (flag_generate_lto)
865 {
866 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
867 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
868 "__gnu_lto_v1",
869 (unsigned HOST_WIDE_INT) 1, 8);
870 #elif defined ASM_OUTPUT_ALIGNED_COMMON
871 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
872 (unsigned HOST_WIDE_INT) 1, 8);
873 #else
874 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
875 (unsigned HOST_WIDE_INT) 1,
876 (unsigned HOST_WIDE_INT) 1);
877 #endif
878 }
879
880 /* Attach a special .ident directive to the end of the file to identify
881 the version of GCC which compiled this code. The format of the .ident
882 string is patterned after the ones produced by native SVR4 compilers. */
883 #ifdef IDENT_ASM_OP
884 if (!flag_no_ident)
885 {
886 const char *pkg_version = "(GNU) ";
887
888 if (strcmp ("(GCC) ", pkgversion_string))
889 pkg_version = pkgversion_string;
890 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
891 IDENT_ASM_OP, pkg_version, version_string);
892 }
893 #endif
894
895 /* Invoke registered plugin callbacks. */
896 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
897
898 /* This must be at the end. Some target ports emit end of file directives
899 into the assembly file here, and hence we can not output anything to the
900 assembly file after this point. */
901 targetm.asm_out.file_end ();
902 }
903
904 /* Indexed by enum debug_info_type. */
905 const char *const debug_type_names[] =
906 {
907 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
908 };
909
910 /* Print version information to FILE.
911 Each line begins with INDENT (for the case where FILE is the
912 assembler output file). */
913
914 void
915 print_version (FILE *file, const char *indent)
916 {
917 static const char fmt1[] =
918 #ifdef __GNUC__
919 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
920 #else
921 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
922 #endif
923 ;
924 static const char fmt2[] =
925 N_("GMP version %s, MPFR version %s, MPC version %s\n");
926 static const char fmt3[] =
927 N_("%s%swarning: %s header version %s differs from library version %s.\n");
928 static const char fmt4[] =
929 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
930 #ifndef __VERSION__
931 #define __VERSION__ "[?]"
932 #endif
933 fprintf (file,
934 file == stderr ? _(fmt1) : fmt1,
935 indent, *indent != 0 ? " " : "",
936 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
937 indent, __VERSION__);
938
939 /* We need to stringify the GMP macro values. Ugh, gmp_version has
940 two string formats, "i.j.k" and "i.j" when k is zero. As of
941 gmp-4.3.0, GMP always uses the 3 number format. */
942 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
943 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
944 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
945 #define GCC_GMP_VERSION \
946 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
947 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
948 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
949 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
950 #else
951 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
952 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
953 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
954 #endif
955 fprintf (file,
956 file == stderr ? _(fmt2) : fmt2,
957 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
958 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
959 fprintf (file,
960 file == stderr ? _(fmt3) : fmt3,
961 indent, *indent != 0 ? " " : "",
962 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
963 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
964 fprintf (file,
965 file == stderr ? _(fmt3) : fmt3,
966 indent, *indent != 0 ? " " : "",
967 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
968 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
969 fprintf (file,
970 file == stderr ? _(fmt3) : fmt3,
971 indent, *indent != 0 ? " " : "",
972 "MPC", MPC_VERSION_STRING, mpc_get_version ());
973 fprintf (file,
974 file == stderr ? _(fmt4) : fmt4,
975 indent, *indent != 0 ? " " : "",
976 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
977
978 print_plugins_versions (file, indent);
979 }
980
981 #ifdef ASM_COMMENT_START
982 static int
983 print_to_asm_out_file (print_switch_type type, const char * text)
984 {
985 bool prepend_sep = true;
986
987 switch (type)
988 {
989 case SWITCH_TYPE_LINE_END:
990 putc ('\n', asm_out_file);
991 return 1;
992
993 case SWITCH_TYPE_LINE_START:
994 fputs (ASM_COMMENT_START, asm_out_file);
995 return strlen (ASM_COMMENT_START);
996
997 case SWITCH_TYPE_DESCRIPTIVE:
998 if (ASM_COMMENT_START[0] == 0)
999 prepend_sep = false;
1000 /* Drop through. */
1001 case SWITCH_TYPE_PASSED:
1002 case SWITCH_TYPE_ENABLED:
1003 if (prepend_sep)
1004 fputc (' ', asm_out_file);
1005 fputs (text, asm_out_file);
1006 /* No need to return the length here as
1007 print_single_switch has already done it. */
1008 return 0;
1009
1010 default:
1011 return -1;
1012 }
1013 }
1014 #endif
1015
1016 static int
1017 print_to_stderr (print_switch_type type, const char * text)
1018 {
1019 switch (type)
1020 {
1021 case SWITCH_TYPE_LINE_END:
1022 putc ('\n', stderr);
1023 return 1;
1024
1025 case SWITCH_TYPE_LINE_START:
1026 return 0;
1027
1028 case SWITCH_TYPE_PASSED:
1029 case SWITCH_TYPE_ENABLED:
1030 fputc (' ', stderr);
1031 /* Drop through. */
1032
1033 case SWITCH_TYPE_DESCRIPTIVE:
1034 fputs (text, stderr);
1035 /* No need to return the length here as
1036 print_single_switch has already done it. */
1037 return 0;
1038
1039 default:
1040 return -1;
1041 }
1042 }
1043
1044 /* Print an option value and return the adjusted position in the line.
1045 ??? print_fn doesn't handle errors, eg disk full; presumably other
1046 code will catch a disk full though. */
1047
1048 static int
1049 print_single_switch (print_switch_fn_type print_fn,
1050 int pos,
1051 print_switch_type type,
1052 const char * text)
1053 {
1054 /* The ultrix fprintf returns 0 on success, so compute the result
1055 we want here since we need it for the following test. The +1
1056 is for the separator character that will probably be emitted. */
1057 int len = strlen (text) + 1;
1058
1059 if (pos != 0
1060 && pos + len > MAX_LINE)
1061 {
1062 print_fn (SWITCH_TYPE_LINE_END, NULL);
1063 pos = 0;
1064 }
1065
1066 if (pos == 0)
1067 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1068
1069 print_fn (type, text);
1070 return pos + len;
1071 }
1072
1073 /* Print active target switches using PRINT_FN.
1074 POS is the current cursor position and MAX is the size of a "line".
1075 Each line begins with INDENT and ends with TERM.
1076 Each switch is separated from the next by SEP. */
1077
1078 static void
1079 print_switch_values (print_switch_fn_type print_fn)
1080 {
1081 int pos = 0;
1082 size_t j;
1083
1084 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1085 that it can be printed below. This helps reproducibility. */
1086 if (!flag_random_seed)
1087 init_random_seed ();
1088
1089 /* Print the options as passed. */
1090 pos = print_single_switch (print_fn, pos,
1091 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1092
1093 for (j = 1; j < save_decoded_options_count; j++)
1094 {
1095 switch (save_decoded_options[j].opt_index)
1096 {
1097 case OPT_o:
1098 case OPT_d:
1099 case OPT_dumpbase:
1100 case OPT_dumpdir:
1101 case OPT_auxbase:
1102 case OPT_quiet:
1103 case OPT_version:
1104 /* Ignore these. */
1105 continue;
1106 }
1107
1108 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
1109 save_decoded_options[j].orig_option_with_args_text);
1110 }
1111
1112 if (pos > 0)
1113 print_fn (SWITCH_TYPE_LINE_END, NULL);
1114
1115 /* Print the -f and -m options that have been enabled.
1116 We don't handle language specific options but printing argv
1117 should suffice. */
1118 pos = print_single_switch (print_fn, 0,
1119 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1120
1121 for (j = 0; j < cl_options_count; j++)
1122 if ((cl_options[j].flags & CL_REPORT)
1123 && option_enabled (j, &global_options) > 0)
1124 pos = print_single_switch (print_fn, pos,
1125 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1126
1127 print_fn (SWITCH_TYPE_LINE_END, NULL);
1128 }
1129
1130 /* Open assembly code output file. Do this even if -fsyntax-only is
1131 on, because then the driver will have provided the name of a
1132 temporary file or bit bucket for us. NAME is the file specified on
1133 the command line, possibly NULL. */
1134 static void
1135 init_asm_output (const char *name)
1136 {
1137 if (name == NULL && asm_file_name == 0)
1138 asm_out_file = stdout;
1139 else
1140 {
1141 if (asm_file_name == 0)
1142 {
1143 int len = strlen (dump_base_name);
1144 char *dumpname = XNEWVEC (char, len + 6);
1145
1146 memcpy (dumpname, dump_base_name, len + 1);
1147 strip_off_ending (dumpname, len);
1148 strcat (dumpname, ".s");
1149 asm_file_name = dumpname;
1150 }
1151 if (!strcmp (asm_file_name, "-"))
1152 asm_out_file = stdout;
1153 else
1154 asm_out_file = fopen (asm_file_name, "w+b");
1155 if (asm_out_file == 0)
1156 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1157 }
1158
1159 if (!flag_syntax_only)
1160 {
1161 targetm.asm_out.file_start ();
1162
1163 if (flag_record_gcc_switches)
1164 {
1165 if (targetm.asm_out.record_gcc_switches)
1166 {
1167 /* Let the target know that we are about to start recording. */
1168 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1169 NULL);
1170 /* Now record the switches. */
1171 print_switch_values (targetm.asm_out.record_gcc_switches);
1172 /* Let the target know that the recording is over. */
1173 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1174 NULL);
1175 }
1176 else
1177 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1178 }
1179
1180 #ifdef ASM_COMMENT_START
1181 if (flag_verbose_asm)
1182 {
1183 /* Print the list of switches in effect
1184 into the assembler file as comments. */
1185 print_version (asm_out_file, ASM_COMMENT_START);
1186 print_switch_values (print_to_asm_out_file);
1187 putc ('\n', asm_out_file);
1188 }
1189 #endif
1190 }
1191 }
1192
1193 /* Return true if the state of option OPTION should be stored in PCH files
1194 and checked by default_pch_valid_p. Store the option's current state
1195 in STATE if so. */
1196
1197 static inline bool
1198 option_affects_pch_p (int option, struct cl_option_state *state)
1199 {
1200 if ((cl_options[option].flags & CL_TARGET) == 0)
1201 return false;
1202 if (option_flag_var (option, &global_options) == &target_flags)
1203 if (targetm.check_pch_target_flags)
1204 return false;
1205 return get_option_state (&global_options, option, state);
1206 }
1207
1208 /* Default version of get_pch_validity.
1209 By default, every flag difference is fatal; that will be mostly right for
1210 most targets, but completely right for very few. */
1211
1212 void *
1213 default_get_pch_validity (size_t *sz)
1214 {
1215 struct cl_option_state state;
1216 size_t i;
1217 char *result, *r;
1218
1219 *sz = 2;
1220 if (targetm.check_pch_target_flags)
1221 *sz += sizeof (target_flags);
1222 for (i = 0; i < cl_options_count; i++)
1223 if (option_affects_pch_p (i, &state))
1224 *sz += state.size;
1225
1226 result = r = XNEWVEC (char, *sz);
1227 r[0] = flag_pic;
1228 r[1] = flag_pie;
1229 r += 2;
1230 if (targetm.check_pch_target_flags)
1231 {
1232 memcpy (r, &target_flags, sizeof (target_flags));
1233 r += sizeof (target_flags);
1234 }
1235
1236 for (i = 0; i < cl_options_count; i++)
1237 if (option_affects_pch_p (i, &state))
1238 {
1239 memcpy (r, state.data, state.size);
1240 r += state.size;
1241 }
1242
1243 return result;
1244 }
1245
1246 /* Return a message which says that a PCH file was created with a different
1247 setting of OPTION. */
1248
1249 static const char *
1250 pch_option_mismatch (const char *option)
1251 {
1252 char *r;
1253
1254 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1255 if (r == NULL)
1256 return _("out of memory");
1257 return r;
1258 }
1259
1260 /* Default version of pch_valid_p. */
1261
1262 const char *
1263 default_pch_valid_p (const void *data_p, size_t len)
1264 {
1265 struct cl_option_state state;
1266 const char *data = (const char *)data_p;
1267 size_t i;
1268
1269 /* -fpic and -fpie also usually make a PCH invalid. */
1270 if (data[0] != flag_pic)
1271 return _("created and used with different settings of -fpic");
1272 if (data[1] != flag_pie)
1273 return _("created and used with different settings of -fpie");
1274 data += 2;
1275
1276 /* Check target_flags. */
1277 if (targetm.check_pch_target_flags)
1278 {
1279 int tf;
1280 const char *r;
1281
1282 memcpy (&tf, data, sizeof (target_flags));
1283 data += sizeof (target_flags);
1284 len -= sizeof (target_flags);
1285 r = targetm.check_pch_target_flags (tf);
1286 if (r != NULL)
1287 return r;
1288 }
1289
1290 for (i = 0; i < cl_options_count; i++)
1291 if (option_affects_pch_p (i, &state))
1292 {
1293 if (memcmp (data, state.data, state.size) != 0)
1294 return pch_option_mismatch (cl_options[i].opt_text);
1295 data += state.size;
1296 len -= state.size;
1297 }
1298
1299 return NULL;
1300 }
1301
1302 /* Default tree printer. Handles declarations only. */
1303 bool
1304 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1305 int precision, bool wide, bool set_locus, bool hash)
1306 {
1307 tree t;
1308
1309 /* FUTURE: %+x should set the locus. */
1310 if (precision != 0 || wide || hash)
1311 return false;
1312
1313 switch (*spec)
1314 {
1315 case 'E':
1316 t = va_arg (*text->args_ptr, tree);
1317 if (TREE_CODE (t) == IDENTIFIER_NODE)
1318 {
1319 pp_identifier (pp, IDENTIFIER_POINTER (t));
1320 return true;
1321 }
1322 break;
1323
1324 case 'D':
1325 t = va_arg (*text->args_ptr, tree);
1326 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1327 t = DECL_DEBUG_EXPR (t);
1328 break;
1329
1330 case 'F':
1331 case 'T':
1332 t = va_arg (*text->args_ptr, tree);
1333 break;
1334
1335 case 'K':
1336 percent_K_format (text);
1337 return true;
1338
1339 default:
1340 return false;
1341 }
1342
1343 if (set_locus && text->locus)
1344 *text->locus = DECL_SOURCE_LOCATION (t);
1345
1346 if (DECL_P (t))
1347 {
1348 const char *n = DECL_NAME (t)
1349 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1350 : _("<anonymous>");
1351 pp_string (pp, n);
1352 }
1353 else
1354 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1355
1356 return true;
1357 }
1358
1359 /* A helper function; used as the reallocator function for cpp's line
1360 table. */
1361 static void *
1362 realloc_for_line_map (void *ptr, size_t len)
1363 {
1364 return GGC_RESIZEVAR (void, ptr, len);
1365 }
1366
1367 /* A helper function: used as the allocator function for
1368 identifier_to_locale. */
1369 static void *
1370 alloc_for_identifier_to_locale (size_t len)
1371 {
1372 return ggc_alloc_atomic (len);
1373 }
1374
1375 /* Output stack usage information. */
1376 void
1377 output_stack_usage (void)
1378 {
1379 static bool warning_issued = false;
1380 enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
1381 const char *stack_usage_kind_str[] = {
1382 "static",
1383 "dynamic",
1384 "dynamic,bounded"
1385 };
1386 HOST_WIDE_INT stack_usage = current_function_static_stack_size;
1387 enum stack_usage_kind_type stack_usage_kind;
1388 expanded_location loc;
1389 const char *raw_id, *id;
1390
1391 if (stack_usage < 0)
1392 {
1393 if (!warning_issued)
1394 {
1395 warning (0, "-fstack-usage not supported for this target");
1396 warning_issued = true;
1397 }
1398 return;
1399 }
1400
1401 stack_usage_kind = STATIC;
1402
1403 /* Add the maximum amount of space pushed onto the stack. */
1404 if (current_function_pushed_stack_size > 0)
1405 {
1406 stack_usage += current_function_pushed_stack_size;
1407 stack_usage_kind = DYNAMIC_BOUNDED;
1408 }
1409
1410 /* Now on to the tricky part: dynamic stack allocation. */
1411 if (current_function_allocates_dynamic_stack_space)
1412 {
1413 if (current_function_has_unbounded_dynamic_stack_size)
1414 stack_usage_kind = DYNAMIC;
1415 else
1416 stack_usage_kind = DYNAMIC_BOUNDED;
1417
1418 /* Add the size even in the unbounded case, this can't hurt. */
1419 stack_usage += current_function_dynamic_stack_size;
1420 }
1421
1422 loc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1423
1424 /* Strip the scope prefix if any. */
1425 raw_id = lang_hooks.decl_printable_name (current_function_decl, 2);
1426 id = strrchr (raw_id, '.');
1427 if (id)
1428 id++;
1429 else
1430 id = raw_id;
1431
1432 fprintf (stack_usage_file,
1433 "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
1434 lbasename (loc.file),
1435 loc.line,
1436 loc.column,
1437 id,
1438 stack_usage,
1439 stack_usage_kind_str[stack_usage_kind]);
1440 }
1441
1442 /* Open an auxiliary output file. */
1443 static FILE *
1444 open_auxiliary_file (const char *ext)
1445 {
1446 char *filename;
1447 FILE *file;
1448
1449 filename = concat (aux_base_name, ".", ext, NULL);
1450 file = fopen (filename, "w");
1451 if (!file)
1452 fatal_error ("can%'t open %s for writing: %m", filename);
1453 free (filename);
1454 return file;
1455 }
1456
1457 /* Initialization of the front end environment, before command line
1458 options are parsed. Signal handlers, internationalization etc.
1459 ARGV0 is main's argv[0]. */
1460 static void
1461 general_init (const char *argv0)
1462 {
1463 const char *p;
1464
1465 p = argv0 + strlen (argv0);
1466 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1467 --p;
1468 progname = p;
1469
1470 xmalloc_set_program_name (progname);
1471
1472 hex_init ();
1473
1474 /* Unlock the stdio streams. */
1475 unlock_std_streams ();
1476
1477 gcc_init_libintl ();
1478
1479 identifier_to_locale_alloc = alloc_for_identifier_to_locale;
1480 identifier_to_locale_free = ggc_free;
1481
1482 /* Initialize the diagnostics reporting machinery, so option parsing
1483 can give warnings and errors. */
1484 diagnostic_initialize (global_dc, N_OPTS);
1485 diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
1486 /* Set a default printer. Language specific initializations will
1487 override it later. */
1488 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1489 global_dc->show_option_requested
1490 = global_options_init.x_flag_diagnostics_show_option;
1491 global_dc->show_column
1492 = global_options_init.x_flag_show_column;
1493 global_dc->internal_error = plugins_internal_error_function;
1494 global_dc->option_enabled = option_enabled;
1495 global_dc->option_state = &global_options;
1496 global_dc->option_name = option_name;
1497
1498 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1499 #ifdef SIGSEGV
1500 signal (SIGSEGV, crash_signal);
1501 #endif
1502 #ifdef SIGILL
1503 signal (SIGILL, crash_signal);
1504 #endif
1505 #ifdef SIGBUS
1506 signal (SIGBUS, crash_signal);
1507 #endif
1508 #ifdef SIGABRT
1509 signal (SIGABRT, crash_signal);
1510 #endif
1511 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1512 signal (SIGIOT, crash_signal);
1513 #endif
1514 #ifdef SIGFPE
1515 signal (SIGFPE, crash_signal);
1516 #endif
1517
1518 /* Other host-specific signal setup. */
1519 (*host_hooks.extra_signals)();
1520
1521 /* Initialize the garbage-collector, string pools and tree type hash
1522 table. */
1523 init_ggc ();
1524 init_stringpool ();
1525 line_table = ggc_alloc_line_maps ();
1526 linemap_init (line_table);
1527 line_table->reallocator = realloc_for_line_map;
1528 init_ttree ();
1529
1530 /* Initialize register usage now so switches may override. */
1531 init_reg_sets ();
1532
1533 /* Register the language-independent parameters. */
1534 add_params (lang_independent_params, LAST_PARAM);
1535 targetm.target_option.default_params ();
1536
1537 /* This must be done after add_params but before argument processing. */
1538 init_ggc_heuristics();
1539 init_optimization_passes ();
1540 statistics_early_init ();
1541 finish_params ();
1542 }
1543
1544 /* Return true if the current target supports -fsection-anchors. */
1545
1546 static bool
1547 target_supports_section_anchors_p (void)
1548 {
1549 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1550 return false;
1551
1552 if (targetm.asm_out.output_anchor == NULL)
1553 return false;
1554
1555 return true;
1556 }
1557
1558 /* Default the align_* variables to 1 if they're still unset, and
1559 set up the align_*_log variables. */
1560 static void
1561 init_alignments (void)
1562 {
1563 if (align_loops <= 0)
1564 align_loops = 1;
1565 if (align_loops_max_skip > align_loops)
1566 align_loops_max_skip = align_loops - 1;
1567 align_loops_log = floor_log2 (align_loops * 2 - 1);
1568 if (align_jumps <= 0)
1569 align_jumps = 1;
1570 if (align_jumps_max_skip > align_jumps)
1571 align_jumps_max_skip = align_jumps - 1;
1572 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1573 if (align_labels <= 0)
1574 align_labels = 1;
1575 align_labels_log = floor_log2 (align_labels * 2 - 1);
1576 if (align_labels_max_skip > align_labels)
1577 align_labels_max_skip = align_labels - 1;
1578 if (align_functions <= 0)
1579 align_functions = 1;
1580 align_functions_log = floor_log2 (align_functions * 2 - 1);
1581 }
1582
1583 /* Process the options that have been parsed. */
1584 static void
1585 process_options (void)
1586 {
1587 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1588 This can happen with incorrect pre-processed input. */
1589 debug_hooks = &do_nothing_debug_hooks;
1590
1591 maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
1592
1593 /* This replaces set_Wunused. */
1594 if (warn_unused_function == -1)
1595 warn_unused_function = warn_unused;
1596 if (warn_unused_label == -1)
1597 warn_unused_label = warn_unused;
1598 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1599 if (warn_unused_parameter == -1)
1600 warn_unused_parameter = (warn_unused && extra_warnings);
1601 if (warn_unused_variable == -1)
1602 warn_unused_variable = warn_unused;
1603 /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
1604 enabled. */
1605 if (warn_unused_but_set_parameter == -1)
1606 warn_unused_but_set_parameter = (warn_unused && extra_warnings);
1607 if (warn_unused_but_set_variable == -1)
1608 warn_unused_but_set_variable = warn_unused;
1609 if (warn_unused_value == -1)
1610 warn_unused_value = warn_unused;
1611
1612 /* This replaces set_Wextra. */
1613 if (warn_uninitialized == -1)
1614 warn_uninitialized = extra_warnings;
1615
1616 /* Allow the front end to perform consistency checks and do further
1617 initialization based on the command line options. This hook also
1618 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1619 so we can correctly initialize debug output. */
1620 no_backend = lang_hooks.post_options (&main_input_filename);
1621
1622 /* Some machines may reject certain combinations of options. */
1623 targetm.target_option.override ();
1624
1625 /* Avoid any informative notes in the second run of -fcompare-debug. */
1626 if (flag_compare_debug)
1627 diagnostic_inhibit_notes (global_dc);
1628
1629 if (flag_section_anchors && !target_supports_section_anchors_p ())
1630 {
1631 warning (OPT_fsection_anchors,
1632 "this target does not support %qs", "-fsection-anchors");
1633 flag_section_anchors = 0;
1634 }
1635
1636 if (flag_short_enums == 2)
1637 flag_short_enums = targetm.default_short_enums ();
1638
1639 /* Set aux_base_name if not already set. */
1640 if (aux_base_name)
1641 ;
1642 else if (main_input_filename)
1643 {
1644 char *name = xstrdup (lbasename (main_input_filename));
1645
1646 strip_off_ending (name, strlen (name));
1647 aux_base_name = name;
1648 }
1649 else
1650 aux_base_name = "gccaux";
1651
1652 #ifndef HAVE_cloog
1653 if (flag_graphite
1654 || flag_loop_block
1655 || flag_loop_interchange
1656 || flag_loop_strip_mine
1657 || flag_graphite_identity
1658 || flag_loop_parallelize_all)
1659 sorry ("Graphite loop optimizations cannot be used");
1660 #endif
1661
1662 /* Unrolling all loops implies that standard loop unrolling must also
1663 be done. */
1664 if (flag_unroll_all_loops)
1665 flag_unroll_loops = 1;
1666
1667 /* web and rename-registers help when run after loop unrolling. */
1668 if (flag_web == AUTODETECT_VALUE)
1669 flag_web = flag_unroll_loops || flag_peel_loops;
1670
1671 if (flag_rename_registers == AUTODETECT_VALUE)
1672 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1673
1674 if (flag_non_call_exceptions)
1675 flag_asynchronous_unwind_tables = 1;
1676 if (flag_asynchronous_unwind_tables)
1677 flag_unwind_tables = 1;
1678
1679 if (flag_value_profile_transformations)
1680 flag_profile_values = 1;
1681
1682 /* Warn about options that are not supported on this machine. */
1683 #ifndef INSN_SCHEDULING
1684 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1685 warning (0, "instruction scheduling not supported on this target machine");
1686 #endif
1687 #ifndef DELAY_SLOTS
1688 if (flag_delayed_branch)
1689 warning (0, "this target machine does not have delayed branches");
1690 #endif
1691
1692 user_label_prefix = USER_LABEL_PREFIX;
1693 if (flag_leading_underscore != -1)
1694 {
1695 /* If the default prefix is more complicated than "" or "_",
1696 issue a warning and ignore this option. */
1697 if (user_label_prefix[0] == 0 ||
1698 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1699 {
1700 user_label_prefix = flag_leading_underscore ? "_" : "";
1701 }
1702 else
1703 warning (0, "-f%sleading-underscore not supported on this target machine",
1704 flag_leading_underscore ? "" : "no-");
1705 }
1706
1707 /* If we are in verbose mode, write out the version and maybe all the
1708 option flags in use. */
1709 if (version_flag)
1710 {
1711 print_version (stderr, "");
1712 if (! quiet_flag)
1713 print_switch_values (print_to_stderr);
1714 }
1715
1716 if (flag_syntax_only)
1717 {
1718 write_symbols = NO_DEBUG;
1719 profile_flag = 0;
1720 }
1721
1722 if (flag_gtoggle)
1723 {
1724 if (debug_info_level == DINFO_LEVEL_NONE)
1725 {
1726 debug_info_level = DINFO_LEVEL_NORMAL;
1727
1728 if (write_symbols == NO_DEBUG)
1729 write_symbols = PREFERRED_DEBUGGING_TYPE;
1730 }
1731 else
1732 debug_info_level = DINFO_LEVEL_NONE;
1733 }
1734
1735 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1736 {
1737 FILE *final_output = fopen (flag_dump_final_insns, "w");
1738 if (!final_output)
1739 {
1740 error ("could not open final insn dump file %qs: %m",
1741 flag_dump_final_insns);
1742 flag_dump_final_insns = NULL;
1743 }
1744 else if (fclose (final_output))
1745 {
1746 error ("could not close zeroed insn dump file %qs: %m",
1747 flag_dump_final_insns);
1748 flag_dump_final_insns = NULL;
1749 }
1750 }
1751
1752 /* Unless over-ridden for the target, assume that all DWARF levels
1753 may be emitted, if DWARF2_DEBUG is selected. */
1754 if (dwarf_strict < 0)
1755 dwarf_strict = 0;
1756
1757 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1758 level is 0. */
1759 if (debug_info_level == DINFO_LEVEL_NONE)
1760 write_symbols = NO_DEBUG;
1761
1762 if (write_symbols == NO_DEBUG)
1763 ;
1764 #if defined(DBX_DEBUGGING_INFO)
1765 else if (write_symbols == DBX_DEBUG)
1766 debug_hooks = &dbx_debug_hooks;
1767 #endif
1768 #if defined(XCOFF_DEBUGGING_INFO)
1769 else if (write_symbols == XCOFF_DEBUG)
1770 debug_hooks = &xcoff_debug_hooks;
1771 #endif
1772 #ifdef SDB_DEBUGGING_INFO
1773 else if (write_symbols == SDB_DEBUG)
1774 debug_hooks = &sdb_debug_hooks;
1775 #endif
1776 #ifdef DWARF2_DEBUGGING_INFO
1777 else if (write_symbols == DWARF2_DEBUG)
1778 debug_hooks = &dwarf2_debug_hooks;
1779 #endif
1780 #ifdef VMS_DEBUGGING_INFO
1781 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1782 debug_hooks = &vmsdbg_debug_hooks;
1783 #endif
1784 else
1785 error ("target system does not support the \"%s\" debug format",
1786 debug_type_names[write_symbols]);
1787
1788 /* We know which debug output will be used so we can set flag_var_tracking
1789 and flag_var_tracking_uninit if the user has not specified them. */
1790 if (debug_info_level < DINFO_LEVEL_NORMAL
1791 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1792 {
1793 if (flag_var_tracking == 1
1794 || flag_var_tracking_uninit == 1)
1795 {
1796 if (debug_info_level < DINFO_LEVEL_NORMAL)
1797 warning (0, "variable tracking requested, but useless unless "
1798 "producing debug info");
1799 else
1800 warning (0, "variable tracking requested, but not supported "
1801 "by this debug format");
1802 }
1803 flag_var_tracking = 0;
1804 flag_var_tracking_uninit = 0;
1805 }
1806
1807 /* The debug hooks are used to implement -fdump-go-spec because it
1808 gives a simple and stable API for all the information we need to
1809 dump. */
1810 if (flag_dump_go_spec != NULL)
1811 debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
1812
1813 /* If the user specifically requested variable tracking with tagging
1814 uninitialized variables, we need to turn on variable tracking.
1815 (We already determined above that variable tracking is feasible.) */
1816 if (flag_var_tracking_uninit)
1817 flag_var_tracking = 1;
1818
1819 if (flag_var_tracking == AUTODETECT_VALUE)
1820 flag_var_tracking = optimize >= 1;
1821
1822 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
1823 flag_var_tracking_assignments = flag_var_tracking
1824 && !(flag_selective_scheduling || flag_selective_scheduling2);
1825
1826 if (flag_var_tracking_assignments_toggle)
1827 flag_var_tracking_assignments = !flag_var_tracking_assignments;
1828
1829 if (flag_var_tracking_assignments && !flag_var_tracking)
1830 flag_var_tracking = flag_var_tracking_assignments = -1;
1831
1832 if (flag_var_tracking_assignments
1833 && (flag_selective_scheduling || flag_selective_scheduling2))
1834 warning (0, "var-tracking-assignments changes selective scheduling");
1835
1836 if (flag_tree_cselim == AUTODETECT_VALUE)
1837 #ifdef HAVE_conditional_move
1838 flag_tree_cselim = 1;
1839 #else
1840 flag_tree_cselim = 0;
1841 #endif
1842
1843 /* If auxiliary info generation is desired, open the output file.
1844 This goes in the same directory as the source file--unlike
1845 all the other output files. */
1846 if (flag_gen_aux_info)
1847 {
1848 aux_info_file = fopen (aux_info_file_name, "w");
1849 if (aux_info_file == 0)
1850 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1851 }
1852
1853 if (! targetm.have_named_sections)
1854 {
1855 if (flag_function_sections)
1856 {
1857 warning (0, "-ffunction-sections not supported for this target");
1858 flag_function_sections = 0;
1859 }
1860 if (flag_data_sections)
1861 {
1862 warning (0, "-fdata-sections not supported for this target");
1863 flag_data_sections = 0;
1864 }
1865 }
1866
1867 if (flag_function_sections && profile_flag)
1868 {
1869 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1870 flag_function_sections = 0;
1871 }
1872
1873 #ifndef HAVE_prefetch
1874 if (flag_prefetch_loop_arrays > 0)
1875 {
1876 warning (0, "-fprefetch-loop-arrays not supported for this target");
1877 flag_prefetch_loop_arrays = 0;
1878 }
1879 #else
1880 if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
1881 {
1882 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1883 flag_prefetch_loop_arrays = 0;
1884 }
1885 #endif
1886
1887 /* This combination of options isn't handled for i386 targets and doesn't
1888 make much sense anyway, so don't allow it. */
1889 if (flag_prefetch_loop_arrays > 0 && optimize_size)
1890 {
1891 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1892 flag_prefetch_loop_arrays = 0;
1893 }
1894
1895 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1896 if (flag_signaling_nans)
1897 flag_trapping_math = 1;
1898
1899 /* We cannot reassociate if we want traps or signed zeros. */
1900 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1901 {
1902 warning (0, "-fassociative-math disabled; other options take precedence");
1903 flag_associative_math = 0;
1904 }
1905
1906 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1907 if (flag_cx_limited_range)
1908 flag_complex_method = 0;
1909
1910 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1911 if (flag_cx_fortran_rules)
1912 flag_complex_method = 1;
1913
1914 /* Targets must be able to place spill slots at lower addresses. If the
1915 target already uses a soft frame pointer, the transition is trivial. */
1916 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1917 {
1918 warning (0, "-fstack-protector not supported for this target");
1919 flag_stack_protect = 0;
1920 }
1921 if (!flag_stack_protect)
1922 warn_stack_protect = 0;
1923
1924 /* ??? Unwind info is not correct around the CFG unless either a frame
1925 pointer is present or A_O_A is set. Fixing this requires rewriting
1926 unwind info generation to be aware of the CFG and propagating states
1927 around edges. */
1928 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1929 && flag_omit_frame_pointer)
1930 {
1931 warning (0, "unwind tables currently require a frame pointer "
1932 "for correctness");
1933 flag_omit_frame_pointer = 0;
1934 }
1935
1936 /* Save the current optimization options. */
1937 optimization_default_node = build_optimization_node ();
1938 optimization_current_node = optimization_default_node;
1939 }
1940
1941 /* This function can be called multiple times to reinitialize the compiler
1942 back end when register classes or instruction sets have changed,
1943 before each function. */
1944 static void
1945 backend_init_target (void)
1946 {
1947 /* Initialize alignment variables. */
1948 init_alignments ();
1949
1950 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1951 to initialize reg_raw_mode[]. */
1952 init_emit_regs ();
1953
1954 /* This invokes target hooks to set fixed_reg[] etc, which is
1955 mode-dependent. */
1956 init_regs ();
1957
1958 /* This depends on stack_pointer_rtx. */
1959 init_fake_stack_mems ();
1960
1961 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1962 mode-dependent. */
1963 init_alias_target ();
1964
1965 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1966 init_reload ();
1967
1968 /* The following initialization functions need to generate rtl, so
1969 provide a dummy function context for them. */
1970 init_dummy_function_start ();
1971
1972 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1973 on a mode change. */
1974 init_expmed ();
1975
1976 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1977 after a mode change as well. */
1978 caller_save_initialized_p = false;
1979
1980 expand_dummy_function_end ();
1981 }
1982
1983 /* Initialize the compiler back end. This function is called only once,
1984 when starting the compiler. */
1985 static void
1986 backend_init (void)
1987 {
1988 init_emit_once ();
1989
1990 init_rtlanal ();
1991 init_inline_once ();
1992 init_varasm_once ();
1993 save_register_info ();
1994
1995 /* Initialize the target-specific back end pieces. */
1996 ira_init_once ();
1997 backend_init_target ();
1998 }
1999
2000 /* Initialize excess precision settings. */
2001 static void
2002 init_excess_precision (void)
2003 {
2004 /* Adjust excess precision handling based on the target options. If
2005 the front end cannot handle it, flag_excess_precision_cmdline
2006 will already have been set accordingly in the post_options
2007 hook. */
2008 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2009 flag_excess_precision = flag_excess_precision_cmdline;
2010 if (flag_unsafe_math_optimizations)
2011 flag_excess_precision = EXCESS_PRECISION_FAST;
2012 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2013 {
2014 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2015 switch (flt_eval_method)
2016 {
2017 case -1:
2018 case 0:
2019 /* Either the target acts unpredictably (-1) or has all the
2020 operations required not to have excess precision (0). */
2021 flag_excess_precision = EXCESS_PRECISION_FAST;
2022 break;
2023 case 1:
2024 case 2:
2025 /* In these cases, predictable excess precision makes
2026 sense. */
2027 break;
2028 default:
2029 /* Any other implementation-defined FLT_EVAL_METHOD values
2030 require the compiler to handle the associated excess
2031 precision rules in excess_precision_type. */
2032 gcc_unreachable ();
2033 }
2034 }
2035 }
2036
2037 /* Initialize things that are both lang-dependent and target-dependent.
2038 This function can be called more than once if target parameters change. */
2039 static void
2040 lang_dependent_init_target (void)
2041 {
2042 /* This determines excess precision settings. */
2043 init_excess_precision ();
2044
2045 /* This creates various _DECL nodes, so needs to be called after the
2046 front end is initialized. It also depends on the HAVE_xxx macros
2047 generated from the target machine description. */
2048 init_optabs ();
2049
2050 /* The following initialization functions need to generate rtl, so
2051 provide a dummy function context for them. */
2052 init_dummy_function_start ();
2053
2054 /* Do the target-specific parts of expr initialization. */
2055 init_expr_target ();
2056
2057 /* Although the actions of these functions are language-independent,
2058 they use optabs, so we cannot call them from backend_init. */
2059 init_set_costs ();
2060 ira_init ();
2061
2062 expand_dummy_function_end ();
2063 }
2064
2065 /* Language-dependent initialization. Returns nonzero on success. */
2066 static int
2067 lang_dependent_init (const char *name)
2068 {
2069 location_t save_loc = input_location;
2070 if (dump_base_name == 0)
2071 dump_base_name = name && name[0] ? name : "gccdump";
2072
2073 /* Other front-end initialization. */
2074 input_location = BUILTINS_LOCATION;
2075 if (lang_hooks.init () == 0)
2076 return 0;
2077 input_location = save_loc;
2078
2079 init_asm_output (name);
2080
2081 /* If stack usage information is desired, open the output file. */
2082 if (flag_stack_usage)
2083 stack_usage_file = open_auxiliary_file ("su");
2084
2085 /* This creates various _DECL nodes, so needs to be called after the
2086 front end is initialized. */
2087 init_eh ();
2088
2089 /* Do the target-specific parts of the initialization. */
2090 lang_dependent_init_target ();
2091
2092 /* If dbx symbol table desired, initialize writing it and output the
2093 predefined types. */
2094 timevar_push (TV_SYMOUT);
2095
2096 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2097 if (dwarf2out_do_frame ())
2098 dwarf2out_frame_init ();
2099 #endif
2100
2101 /* Now we have the correct original filename, we can initialize
2102 debug output. */
2103 (*debug_hooks->init) (name);
2104
2105 timevar_pop (TV_SYMOUT);
2106
2107 return 1;
2108 }
2109
2110
2111 /* Reinitialize everything when target parameters, such as register usage,
2112 have changed. */
2113 void
2114 target_reinit (void)
2115 {
2116 /* Reinitialize RTL backend. */
2117 backend_init_target ();
2118
2119 /* Reinitialize lang-dependent parts. */
2120 lang_dependent_init_target ();
2121 }
2122
2123 void
2124 dump_memory_report (bool final)
2125 {
2126 ggc_print_statistics ();
2127 stringpool_statistics ();
2128 dump_tree_statistics ();
2129 dump_gimple_statistics ();
2130 dump_rtx_statistics ();
2131 dump_alloc_pool_statistics ();
2132 dump_bitmap_statistics ();
2133 dump_vec_loc_statistics ();
2134 dump_ggc_loc_statistics (final);
2135 dump_alias_stats (stderr);
2136 dump_pta_stats (stderr);
2137 }
2138
2139 /* Clean up: close opened files, etc. */
2140
2141 static void
2142 finalize (bool no_backend)
2143 {
2144 /* Close the dump files. */
2145 if (flag_gen_aux_info)
2146 {
2147 fclose (aux_info_file);
2148 if (seen_error ())
2149 unlink (aux_info_file_name);
2150 }
2151
2152 /* Close non-debugging input and output files. Take special care to note
2153 whether fclose returns an error, since the pages might still be on the
2154 buffer chain while the file is open. */
2155
2156 if (asm_out_file)
2157 {
2158 if (ferror (asm_out_file) != 0)
2159 fatal_error ("error writing to %s: %m", asm_file_name);
2160 if (fclose (asm_out_file) != 0)
2161 fatal_error ("error closing %s: %m", asm_file_name);
2162 if (flag_wpa)
2163 unlink_if_ordinary (asm_file_name);
2164 }
2165
2166 if (stack_usage_file)
2167 fclose (stack_usage_file);
2168
2169 if (!no_backend)
2170 {
2171 statistics_fini ();
2172
2173 finish_optimization_passes ();
2174
2175 ira_finish_once ();
2176 }
2177
2178 if (mem_report)
2179 dump_memory_report (true);
2180
2181 /* Language-specific end of compilation actions. */
2182 lang_hooks.finish ();
2183 }
2184
2185 /* Initialize the compiler, and compile the input file. */
2186 static void
2187 do_compile (void)
2188 {
2189 /* Initialize timing first. The C front ends read the main file in
2190 the post_options hook, and C++ does file timings. */
2191 if (time_report || !quiet_flag || flag_detailed_statistics)
2192 timevar_init ();
2193 timevar_start (TV_TOTAL);
2194
2195 process_options ();
2196
2197 /* Don't do any more if an error has already occurred. */
2198 if (!seen_error ())
2199 {
2200 /* This must be run always, because it is needed to compute the FP
2201 predefined macros, such as __LDBL_MAX__, for targets using non
2202 default FP formats. */
2203 init_adjust_machine_modes ();
2204
2205 /* Set up the back-end if requested. */
2206 if (!no_backend)
2207 backend_init ();
2208
2209 /* Language-dependent initialization. Returns true on success. */
2210 if (lang_dependent_init (main_input_filename))
2211 compile_file ();
2212
2213 finalize (no_backend);
2214 }
2215
2216 /* Stop timing and print the times. */
2217 timevar_stop (TV_TOTAL);
2218 timevar_print (stderr);
2219 }
2220
2221 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2222 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2223 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2224
2225 It is not safe to call this function more than once. */
2226
2227 int
2228 toplev_main (int argc, char **argv)
2229 {
2230 expandargv (&argc, &argv);
2231
2232 /* Initialization of GCC's environment, and diagnostics. */
2233 general_init (argv[0]);
2234
2235 /* One-off initialization of options that does not need to be
2236 repeated when options are added for particular functions. */
2237 init_options_once ();
2238
2239 /* Initialize global options structures; this must be repeated for
2240 each structure used for parsing options. */
2241 init_options_struct (&global_options, &global_options_set);
2242 lang_hooks.init_options_struct (&global_options);
2243
2244 /* Convert the options to an array. */
2245 decode_cmdline_options_to_array_default_mask (argc,
2246 CONST_CAST2 (const char **,
2247 char **, argv),
2248 &save_decoded_options,
2249 &save_decoded_options_count);
2250
2251 /* Perform language-specific options initialization. */
2252 lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
2253
2254 /* Parse the options and do minimal processing; basically just
2255 enough to default flags appropriately. */
2256 decode_options (&global_options, &global_options_set,
2257 save_decoded_options, save_decoded_options_count,
2258 UNKNOWN_LOCATION, global_dc);
2259
2260 handle_common_deferred_options ();
2261
2262 init_local_tick ();
2263
2264 initialize_plugins ();
2265
2266 if (version_flag)
2267 print_version (stderr, "");
2268
2269 if (help_flag)
2270 print_plugins_help (stderr, "");
2271
2272 /* Exit early if we can (e.g. -help). */
2273 if (!exit_after_options)
2274 do_compile ();
2275
2276 if (warningcount || errorcount)
2277 print_ignored_options ();
2278 diagnostic_finish (global_dc);
2279
2280 /* Invoke registered plugin callbacks if any. */
2281 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2282
2283 finalize_plugins ();
2284 if (seen_error ())
2285 return (FATAL_EXIT_CODE);
2286
2287 return (SUCCESS_EXIT_CODE);
2288 }